2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "Array-flags.h" |
2942
|
32 #include "str-vec.h" |
2376
|
33 |
2974
|
34 #include "oct-obj.h" |
2979
|
35 #include "oct-lvalue.h" |
2376
|
36 #include "ov.h" |
|
37 #include "ov-base.h" |
2825
|
38 #include "ov-bool.h" |
|
39 #include "ov-bool-mat.h" |
2376
|
40 #include "ov-scalar.h" |
|
41 #include "ov-re-mat.h" |
|
42 #include "ov-complex.h" |
|
43 #include "ov-cx-mat.h" |
|
44 #include "ov-ch-mat.h" |
|
45 #include "ov-str-mat.h" |
|
46 #include "ov-range.h" |
|
47 #include "ov-struct.h" |
2903
|
48 #include "ov-file.h" |
2880
|
49 #include "ov-list.h" |
2376
|
50 #include "ov-colon.h" |
|
51 #include "ov-va-args.h" |
2974
|
52 #include "ov-builtin.h" |
|
53 #include "ov-mapper.h" |
|
54 #include "ov-usr-fcn.h" |
2376
|
55 #include "ov-typeinfo.h" |
|
56 |
|
57 #include "defun.h" |
2880
|
58 #include "error.h" |
2376
|
59 #include "gripes.h" |
|
60 #include "pager.h" |
|
61 #include "pr-output.h" |
|
62 #include "utils.h" |
|
63 #include "variables.h" |
|
64 |
2477
|
65 // We are likely to have a lot of octave_value objects to allocate, so |
|
66 // make the grow_size large. |
3219
|
67 DEFINE_OCTAVE_ALLOCATOR2(octave_value, 1024); |
2477
|
68 |
2376
|
69 // If TRUE, allow assignments like |
|
70 // |
|
71 // octave> A(1) = 3; A(2) = 5 |
|
72 // |
|
73 // for A already defined and a matrix type. |
|
74 bool Vdo_fortran_indexing; |
|
75 |
|
76 // Should we allow things like: |
|
77 // |
|
78 // octave> 'abc' + 0 |
|
79 // 97 98 99 |
|
80 // |
|
81 // to happen? A positive value means yes. A negative value means |
|
82 // yes, but print a warning message. Zero means it should be |
|
83 // considered an error. |
|
84 int Vimplicit_str_to_num_ok; |
|
85 |
|
86 // Should we allow silent conversion of complex to real when a real |
|
87 // type is what we're really looking for? A positive value means yes. |
|
88 // A negative value means yes, but print a warning message. Zero |
|
89 // means it should be considered an error. |
|
90 int Vok_to_lose_imaginary_part; |
|
91 |
|
92 // If TRUE, create column vectors when doing assignments like: |
|
93 // |
|
94 // octave> A(1) = 3; A(2) = 5 |
|
95 // |
|
96 // (for A undefined). Only matters when resize_on_range_error is also |
|
97 // TRUE. |
|
98 bool Vprefer_column_vectors; |
|
99 |
|
100 // If TRUE, print the name along with the value. |
|
101 bool Vprint_answer_id_name; |
|
102 |
|
103 // Should operations on empty matrices return empty matrices or an |
|
104 // error? A positive value means yes. A negative value means yes, |
|
105 // but print a warning message. Zero means it should be considered an |
|
106 // error. |
|
107 int Vpropagate_empty_matrices; |
|
108 |
|
109 // How many levels of structure elements should we print? |
|
110 int Vstruct_levels_to_print; |
|
111 |
|
112 // Allow divide by zero errors to be suppressed. |
|
113 bool Vwarn_divide_by_zero; |
|
114 |
2948
|
115 // If TRUE, resize matrices when performing and indexed assignment and |
|
116 // the indices are outside the current bounds. |
3196
|
117 bool Vresize_on_range_error; |
2948
|
118 |
2880
|
119 // XXX FIXME XXX |
|
120 |
2376
|
121 // Octave's value type. |
|
122 |
|
123 string |
3203
|
124 octave_value::unary_op_as_string (unary_op op) |
|
125 { |
|
126 string retval; |
|
127 |
|
128 switch (op) |
|
129 { |
|
130 case not: |
|
131 retval = "!"; |
|
132 break; |
|
133 |
|
134 case uminus: |
|
135 retval = "-"; |
|
136 break; |
|
137 |
|
138 case transpose: |
|
139 retval = ".'"; |
|
140 break; |
|
141 |
|
142 case hermitian: |
|
143 retval = "'"; |
|
144 break; |
|
145 |
|
146 case incr: |
|
147 retval = "++"; |
|
148 break; |
|
149 |
|
150 case decr: |
|
151 retval = "--"; |
|
152 break; |
|
153 |
|
154 default: |
|
155 retval = "<unknown>"; |
|
156 } |
|
157 |
|
158 return retval; |
|
159 } |
|
160 |
|
161 string |
2376
|
162 octave_value::binary_op_as_string (binary_op op) |
|
163 { |
|
164 string retval; |
|
165 |
|
166 switch (op) |
|
167 { |
|
168 case add: |
|
169 retval = "+"; |
|
170 break; |
|
171 |
|
172 case sub: |
|
173 retval = "-"; |
|
174 break; |
|
175 |
|
176 case mul: |
|
177 retval = "*"; |
|
178 break; |
|
179 |
|
180 case div: |
|
181 retval = "/"; |
|
182 break; |
|
183 |
|
184 case pow: |
|
185 retval = "^"; |
|
186 break; |
|
187 |
|
188 case ldiv: |
|
189 retval = "\\"; |
|
190 break; |
|
191 |
2903
|
192 case lshift: |
|
193 retval = "<<"; |
|
194 break; |
|
195 |
|
196 case rshift: |
|
197 retval = ">>"; |
|
198 break; |
|
199 |
2376
|
200 case lt: |
|
201 retval = "<"; |
|
202 break; |
|
203 |
|
204 case le: |
|
205 retval = "<="; |
|
206 break; |
|
207 |
|
208 case eq: |
|
209 retval = "=="; |
|
210 break; |
|
211 |
|
212 case ge: |
|
213 retval = ">="; |
|
214 break; |
|
215 |
|
216 case gt: |
|
217 retval = ">"; |
|
218 break; |
|
219 |
|
220 case ne: |
|
221 retval = "!="; |
|
222 break; |
|
223 |
|
224 case el_mul: |
|
225 retval = ".*"; |
|
226 break; |
|
227 |
|
228 case el_div: |
|
229 retval = "./"; |
|
230 break; |
|
231 |
|
232 case el_pow: |
|
233 retval = ".^"; |
|
234 break; |
|
235 |
|
236 case el_ldiv: |
|
237 retval = ".\\"; |
|
238 break; |
|
239 |
|
240 case el_and: |
|
241 retval = "&"; |
|
242 break; |
|
243 |
|
244 case el_or: |
|
245 retval = "|"; |
|
246 break; |
|
247 |
|
248 case struct_ref: |
|
249 retval = "."; |
|
250 break; |
|
251 |
|
252 default: |
|
253 retval = "<unknown>"; |
|
254 } |
|
255 |
|
256 return retval; |
|
257 } |
|
258 |
2880
|
259 string |
|
260 octave_value::assign_op_as_string (assign_op op) |
|
261 { |
|
262 string retval; |
|
263 |
|
264 switch (op) |
|
265 { |
|
266 case asn_eq: |
|
267 retval = "="; |
|
268 break; |
|
269 |
|
270 case add_eq: |
|
271 retval = "+="; |
|
272 break; |
|
273 |
|
274 case sub_eq: |
|
275 retval = "-="; |
|
276 break; |
|
277 |
|
278 case mul_eq: |
|
279 retval = "*="; |
|
280 break; |
|
281 |
|
282 case div_eq: |
|
283 retval = "/="; |
|
284 break; |
|
285 |
3204
|
286 case ldiv_eq: |
|
287 retval = "\\="; |
|
288 break; |
|
289 |
2903
|
290 case lshift_eq: |
|
291 retval = "<<="; |
|
292 break; |
|
293 |
|
294 case rshift_eq: |
|
295 retval = ">>="; |
|
296 break; |
|
297 |
2880
|
298 case el_mul_eq: |
|
299 retval = ".*="; |
|
300 break; |
|
301 |
|
302 case el_div_eq: |
|
303 retval = "./="; |
|
304 break; |
|
305 |
3204
|
306 case el_ldiv_eq: |
|
307 retval = ".\\="; |
|
308 break; |
|
309 |
2880
|
310 case el_and_eq: |
|
311 retval = "&="; |
|
312 break; |
|
313 |
|
314 case el_or_eq: |
|
315 retval = "|="; |
|
316 break; |
|
317 |
|
318 default: |
|
319 retval = "<unknown>"; |
|
320 } |
|
321 |
|
322 return retval; |
|
323 } |
|
324 |
2376
|
325 octave_value::octave_value (void) |
2825
|
326 : rep (new octave_base_value ()) |
|
327 { |
|
328 rep->count = 1; |
|
329 } |
2376
|
330 |
|
331 octave_value::octave_value (double d) |
2825
|
332 : rep (new octave_scalar (d)) |
|
333 { |
|
334 rep->count = 1; |
|
335 } |
2376
|
336 |
|
337 octave_value::octave_value (const Matrix& m) |
2423
|
338 : rep (new octave_matrix (m)) |
|
339 { |
|
340 rep->count = 1; |
|
341 maybe_mutate (); |
|
342 } |
2376
|
343 |
|
344 octave_value::octave_value (const DiagMatrix& d) |
2423
|
345 : rep (new octave_matrix (d)) |
|
346 { |
|
347 rep->count = 1; |
|
348 maybe_mutate (); |
|
349 } |
2376
|
350 |
|
351 octave_value::octave_value (const RowVector& v, int pcv) |
2423
|
352 : rep (new octave_matrix (v, pcv)) |
|
353 { |
|
354 rep->count = 1; |
|
355 maybe_mutate (); |
|
356 } |
2376
|
357 |
|
358 octave_value::octave_value (const ColumnVector& v, int pcv) |
2423
|
359 : rep (new octave_matrix (v, pcv)) |
|
360 { |
|
361 rep->count = 1; |
|
362 maybe_mutate (); |
|
363 } |
2376
|
364 |
|
365 octave_value::octave_value (const Complex& C) |
2423
|
366 : rep (new octave_complex (C)) |
|
367 { |
|
368 rep->count = 1; |
|
369 maybe_mutate (); |
|
370 } |
2376
|
371 |
|
372 octave_value::octave_value (const ComplexMatrix& m) |
2423
|
373 : rep (new octave_complex_matrix (m)) |
|
374 { |
|
375 rep->count = 1; |
|
376 maybe_mutate (); |
|
377 } |
2376
|
378 |
|
379 octave_value::octave_value (const ComplexDiagMatrix& d) |
2423
|
380 : rep (new octave_complex_matrix (d)) |
|
381 { |
|
382 rep->count = 1; |
|
383 maybe_mutate (); |
|
384 } |
2376
|
385 |
|
386 octave_value::octave_value (const ComplexRowVector& v, int pcv) |
2423
|
387 : rep (new octave_complex_matrix (v, pcv)) |
|
388 { |
|
389 rep->count = 1; |
|
390 maybe_mutate (); |
|
391 } |
2376
|
392 |
|
393 octave_value::octave_value (const ComplexColumnVector& v, int pcv) |
2423
|
394 : rep (new octave_complex_matrix (v, pcv)) |
|
395 { |
|
396 rep->count = 1; |
|
397 maybe_mutate (); |
|
398 } |
2376
|
399 |
2825
|
400 octave_value::octave_value (bool b) |
|
401 : rep (new octave_bool (b)) |
|
402 { |
|
403 rep->count = 1; |
|
404 } |
|
405 |
|
406 octave_value::octave_value (const boolMatrix& bm) |
|
407 : rep (new octave_bool_matrix (bm)) |
|
408 { |
|
409 rep->count = 1; |
|
410 maybe_mutate (); |
|
411 } |
|
412 |
3189
|
413 octave_value::octave_value (char c) |
|
414 : rep (new octave_char_matrix_str (c)) |
|
415 { |
|
416 rep->count = 1; |
|
417 maybe_mutate (); |
|
418 } |
|
419 |
2376
|
420 octave_value::octave_value (const char *s) |
2423
|
421 : rep (new octave_char_matrix_str (s)) |
|
422 { |
|
423 rep->count = 1; |
|
424 maybe_mutate (); |
|
425 } |
2376
|
426 |
|
427 octave_value::octave_value (const string& s) |
2423
|
428 : rep (new octave_char_matrix_str (s)) |
|
429 { |
|
430 rep->count = 1; |
|
431 maybe_mutate (); |
|
432 } |
2376
|
433 |
|
434 octave_value::octave_value (const string_vector& s) |
2423
|
435 : rep (new octave_char_matrix_str (s)) |
|
436 { |
|
437 rep->count = 1; |
|
438 maybe_mutate (); |
|
439 } |
2376
|
440 |
|
441 octave_value::octave_value (const charMatrix& chm, bool is_string) |
2409
|
442 : rep (0) |
|
443 { |
|
444 if (is_string) |
|
445 rep = new octave_char_matrix_str (chm); |
|
446 else |
|
447 rep = new octave_char_matrix (chm); |
2376
|
448 |
2409
|
449 rep->count = 1; |
2423
|
450 maybe_mutate (); |
2409
|
451 } |
2376
|
452 |
|
453 octave_value::octave_value (double base, double limit, double inc) |
2423
|
454 : rep (new octave_range (base, limit, inc)) |
|
455 { |
|
456 rep->count = 1; |
|
457 maybe_mutate (); |
|
458 } |
2376
|
459 |
|
460 octave_value::octave_value (const Range& r) |
2423
|
461 : rep (new octave_range (r)) |
|
462 { |
|
463 rep->count = 1; |
|
464 maybe_mutate (); |
|
465 } |
2376
|
466 |
|
467 octave_value::octave_value (const Octave_map& m) |
2825
|
468 : rep (new octave_struct (m)) |
|
469 { |
|
470 rep->count = 1; |
2880
|
471 } |
|
472 |
2903
|
473 octave_value::octave_value (octave_stream *s, int n) |
|
474 : rep (new octave_file (s, n)) |
|
475 { |
|
476 rep->count = 1; |
|
477 } |
|
478 |
2974
|
479 octave_value::octave_value (octave_function *f) |
|
480 : rep (f) |
|
481 { |
|
482 rep->count = 1; |
|
483 } |
|
484 |
2880
|
485 octave_value::octave_value (const octave_value_list& l) |
|
486 : rep (new octave_list (l)) |
|
487 { |
|
488 rep->count = 1; |
|
489 } |
2376
|
490 |
|
491 octave_value::octave_value (octave_value::magic_colon) |
2825
|
492 : rep (new octave_magic_colon ()) |
|
493 { |
|
494 rep->count = 1; |
|
495 } |
2376
|
496 |
|
497 octave_value::octave_value (octave_value::all_va_args) |
2825
|
498 : rep (new octave_all_va_args ()) |
|
499 { |
|
500 rep->count = 1; |
|
501 } |
2376
|
502 |
|
503 octave_value::octave_value (octave_value *new_rep) |
2825
|
504 : rep (new_rep) |
|
505 { |
|
506 rep->count = 1; |
|
507 } |
2376
|
508 |
|
509 octave_value::~octave_value (void) |
|
510 { |
|
511 #if defined (MDEBUG) |
|
512 cerr << "~octave_value: rep: " << rep |
|
513 << " rep->count: " << rep->count << "\n"; |
|
514 #endif |
|
515 |
|
516 if (rep && --rep->count == 0) |
|
517 { |
|
518 delete rep; |
|
519 rep = 0; |
|
520 } |
|
521 } |
|
522 |
2880
|
523 octave_value * |
|
524 octave_value::clone (void) |
|
525 { |
|
526 panic_impossible (); |
|
527 } |
|
528 |
2409
|
529 void |
|
530 octave_value::maybe_mutate (void) |
|
531 { |
2410
|
532 octave_value *tmp = rep->try_narrowing_conversion (); |
2409
|
533 |
|
534 if (tmp && tmp != rep) |
|
535 { |
|
536 if (--rep->count == 0) |
|
537 delete rep; |
|
538 |
|
539 rep = tmp; |
|
540 rep->count = 1; |
|
541 } |
|
542 } |
|
543 |
2974
|
544 octave_value_list |
|
545 octave_value::do_index_op (int nargout, const octave_value_list& idx) |
|
546 { |
|
547 return rep->do_index_op (nargout, idx); |
|
548 } |
|
549 |
2376
|
550 static void |
3203
|
551 gripe_no_conversion (const string& on, const string& tn1, const string& tn2) |
2376
|
552 { |
3203
|
553 error ("operator %s: no conversion for assignment of `%s' to indexed `%s'", |
|
554 on.c_str (), tn2.c_str (), tn1.c_str ()); |
2376
|
555 } |
|
556 |
3204
|
557 static void |
|
558 gripe_assign_failed (const string& on, const string& tn1, const string& tn2) |
|
559 { |
|
560 error ("assignment failed for `%s %s %s'", |
|
561 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
562 } |
|
563 |
|
564 static void |
|
565 gripe_assign_failed_or_no_method (const string& on, const string& tn1, |
|
566 const string& tn2) |
|
567 { |
|
568 error ("assignment failed, or no method for `%s %s %s'", |
|
569 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
570 } |
|
571 |
2963
|
572 void |
3203
|
573 octave_value::assign (assign_op op, const octave_value& rhs) |
2880
|
574 { |
3203
|
575 if (op == asn_eq) |
|
576 operator = (rhs); |
|
577 else |
|
578 { |
3204
|
579 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
580 // a specific function to call to handle the op= operation for |
|
581 // the types we have. |
|
582 |
|
583 binary_op binop = op_eq_to_binary_op (op); |
|
584 |
|
585 if (! error_state) |
|
586 { |
|
587 octave_value t = do_binary_op (binop, *this, rhs); |
|
588 |
|
589 if (! error_state) |
|
590 operator = (t); |
|
591 } |
|
592 |
|
593 if (error_state) |
|
594 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
595 type_name (), rhs.type_name ()); |
|
596 } |
|
597 } |
|
598 |
|
599 void |
|
600 octave_value::simple_assign (octave_value::assign_op orig_op, |
|
601 const octave_value_list& idx, |
|
602 const octave_value& rhs) |
|
603 { |
|
604 make_unique (); |
|
605 |
|
606 bool assignment_ok = try_assignment (asn_eq, idx, rhs); |
|
607 |
|
608 if (! (error_state || assignment_ok)) |
|
609 { |
|
610 assignment_ok = try_assignment_with_conversion (asn_eq, idx, rhs); |
|
611 |
|
612 if (! (error_state || assignment_ok)) |
|
613 gripe_no_conversion (assign_op_as_string (orig_op), |
|
614 type_name (), rhs.type_name ()); |
3203
|
615 } |
2880
|
616 } |
|
617 |
2963
|
618 void |
2880
|
619 octave_value::assign (octave_value::assign_op op, |
|
620 const octave_value_list& idx, |
|
621 const octave_value& rhs) |
2409
|
622 { |
2948
|
623 if (Vresize_on_range_error || is_defined ()) |
|
624 { |
3204
|
625 if (op == asn_eq) |
|
626 simple_assign (op, idx, rhs); |
|
627 else |
|
628 { |
|
629 // XXX FIXME XXX -- only do the following stuff if we can't |
|
630 // find a specific function to call to handle the op= |
|
631 // operation for the types we have. |
|
632 |
|
633 octave_value t1 = *this; |
2948
|
634 |
3204
|
635 t1 = t1.do_index_op (idx); |
|
636 |
|
637 if (! error_state) |
|
638 { |
|
639 binary_op binop = op_eq_to_binary_op (op); |
|
640 |
|
641 if (! error_state) |
|
642 { |
|
643 octave_value t2 = do_binary_op (binop, t1, rhs); |
2948
|
644 |
3204
|
645 if (! error_state) |
|
646 { |
|
647 simple_assign (op, idx, t2); |
2948
|
648 |
3204
|
649 if (error_state) |
|
650 gripe_assign_failed (assign_op_as_string (op), |
|
651 type_name (), rhs.type_name ()); |
|
652 } |
|
653 else |
|
654 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
655 type_name (), |
|
656 rhs.type_name ()); |
|
657 } |
|
658 else |
|
659 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
660 type_name (), |
|
661 rhs.type_name ()); |
|
662 } |
|
663 else |
|
664 gripe_assign_failed (assign_op_as_string (op), |
3203
|
665 type_name (), rhs.type_name ()); |
2948
|
666 } |
|
667 |
|
668 if (! error_state) |
|
669 maybe_mutate (); |
|
670 } |
|
671 else |
|
672 { |
|
673 error ("indexed assignment to previously undefined variables"); |
|
674 error ("is only possible when resize_on_range_error is true"); |
|
675 } |
|
676 } |
|
677 |
|
678 void |
|
679 octave_value::assign_struct_elt (assign_op op, const string& elt_nm, |
|
680 const octave_value& rhs) |
|
681 { |
2409
|
682 make_unique (); |
2376
|
683 |
2948
|
684 rep->assign_struct_elt (op, elt_nm, rhs); |
|
685 } |
|
686 |
2409
|
687 |
2948
|
688 void |
|
689 octave_value::assign_struct_elt (assign_op op, const string& elt_nm, |
|
690 const octave_value_list& idx, |
|
691 const octave_value& rhs) |
|
692 { |
|
693 make_unique (); |
2409
|
694 |
2948
|
695 rep->assign_struct_elt (op, elt_nm, idx, rhs); |
|
696 } |
2376
|
697 |
2979
|
698 octave_lvalue |
2948
|
699 octave_value::struct_elt_ref (const string& nm) |
|
700 { |
|
701 return rep->struct_elt_ref (this, nm); |
|
702 } |
2409
|
703 |
2979
|
704 octave_lvalue |
2948
|
705 octave_value::struct_elt_ref (octave_value *, const string&) |
|
706 { |
|
707 panic_impossible (); |
|
708 |
2979
|
709 return octave_lvalue (); |
2376
|
710 } |
|
711 |
|
712 Octave_map |
|
713 octave_value::map_value (void) const |
|
714 { |
|
715 return rep->map_value (); |
|
716 } |
|
717 |
2903
|
718 octave_stream * |
|
719 octave_value::stream_value (void) const |
|
720 { |
|
721 return rep->stream_value (); |
|
722 } |
|
723 |
|
724 int |
|
725 octave_value::stream_number (void) const |
|
726 { |
|
727 return rep->stream_number (); |
|
728 } |
|
729 |
2974
|
730 octave_function * |
|
731 octave_value::function_value (bool silent) |
|
732 { |
|
733 return rep->function_value (silent); |
|
734 } |
|
735 |
2880
|
736 octave_value_list |
|
737 octave_value::list_value (void) const |
|
738 { |
|
739 return rep->list_value (); |
|
740 } |
|
741 |
2376
|
742 ColumnVector |
|
743 octave_value::vector_value (bool force_string_conv, |
|
744 bool force_vector_conversion) const |
|
745 { |
|
746 ColumnVector retval; |
|
747 |
|
748 Matrix m = matrix_value (force_string_conv); |
|
749 |
|
750 if (error_state) |
|
751 return retval; |
|
752 |
|
753 int nr = m.rows (); |
|
754 int nc = m.columns (); |
|
755 |
|
756 if (nr == 1) |
|
757 { |
|
758 retval.resize (nc); |
|
759 for (int i = 0; i < nc; i++) |
|
760 retval (i) = m (0, i); |
|
761 } |
|
762 else if (nc == 1) |
|
763 { |
|
764 retval.resize (nr); |
|
765 for (int i = 0; i < nr; i++) |
|
766 retval (i) = m (i, 0); |
|
767 } |
|
768 else if (nr > 0 && nc > 0 |
|
769 && (Vdo_fortran_indexing || force_vector_conversion)) |
|
770 { |
|
771 retval.resize (nr * nc); |
|
772 int k = 0; |
|
773 for (int j = 0; j < nc; j++) |
|
774 for (int i = 0; i < nr; i++) |
|
775 retval (k++) = m (i, j); |
|
776 } |
|
777 else |
|
778 { |
|
779 string tn = type_name (); |
|
780 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
781 } |
|
782 |
|
783 return retval; |
|
784 } |
|
785 |
|
786 ComplexColumnVector |
|
787 octave_value::complex_vector_value (bool force_string_conv, |
|
788 bool force_vector_conversion) const |
|
789 { |
|
790 ComplexColumnVector retval; |
|
791 |
|
792 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
793 |
|
794 if (error_state) |
|
795 return retval; |
|
796 |
|
797 int nr = m.rows (); |
|
798 int nc = m.columns (); |
|
799 |
|
800 if (nr == 1) |
|
801 { |
|
802 retval.resize (nc); |
|
803 for (int i = 0; i < nc; i++) |
|
804 retval (i) = m (0, i); |
|
805 } |
|
806 else if (nc == 1) |
|
807 { |
|
808 retval.resize (nr); |
|
809 for (int i = 0; i < nr; i++) |
|
810 retval (i) = m (i, 0); |
|
811 } |
|
812 else if (nr > 0 && nc > 0 |
|
813 && (Vdo_fortran_indexing || force_vector_conversion)) |
|
814 { |
|
815 retval.resize (nr * nc); |
|
816 int k = 0; |
|
817 for (int j = 0; j < nc; j++) |
|
818 for (int i = 0; i < nr; i++) |
|
819 retval (k++) = m (i, j); |
|
820 } |
|
821 else |
|
822 { |
|
823 string tn = type_name (); |
|
824 gripe_invalid_conversion (tn.c_str (), "complex vector"); |
|
825 } |
|
826 |
|
827 return retval; |
|
828 } |
|
829 |
|
830 void |
|
831 octave_value::print_with_name (ostream& output_buf, const string& name, |
2903
|
832 bool print_padding) const |
2376
|
833 { |
2903
|
834 bool pad_after = print_name_tag (output_buf, name); |
2376
|
835 |
|
836 print (output_buf); |
|
837 |
|
838 if (print_padding && pad_after) |
2903
|
839 newline (output_buf); |
2376
|
840 } |
|
841 |
|
842 static void |
2413
|
843 gripe_indexed_assignment (const string& tn1, const string& tn2) |
|
844 { |
2903
|
845 error ("assignment of `%s' to indexed `%s' not implemented", |
2413
|
846 tn2.c_str (), tn1.c_str ()); |
|
847 } |
|
848 |
|
849 static void |
3203
|
850 gripe_assign_conversion_failed (const string& tn1, const string& tn2) |
2413
|
851 { |
2903
|
852 error ("type conversion for assignment of `%s' to indexed `%s' failed", |
2413
|
853 tn2.c_str (), tn1.c_str ()); |
|
854 } |
|
855 |
|
856 bool |
2880
|
857 octave_value::convert_and_assign (octave_value::assign_op op, |
|
858 const octave_value_list& idx, |
2413
|
859 const octave_value& rhs) |
|
860 { |
|
861 bool assignment_ok = false; |
|
862 |
|
863 int t_lhs = type_id (); |
|
864 int t_rhs = rhs.type_id (); |
|
865 |
|
866 int t_result |
|
867 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
868 |
|
869 if (t_result >= 0) |
|
870 { |
2427
|
871 type_conv_fcn cf |
2413
|
872 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
873 |
|
874 if (cf) |
|
875 { |
|
876 octave_value *tmp = cf (*rep); |
|
877 |
|
878 if (tmp) |
|
879 { |
2589
|
880 octave_value *old_rep = rep; |
|
881 rep = tmp; |
|
882 rep->count = 1; |
|
883 |
2880
|
884 assignment_ok = try_assignment (op, idx, rhs); |
2589
|
885 |
|
886 if (! assignment_ok && old_rep) |
2413
|
887 { |
|
888 if (--rep->count == 0) |
|
889 delete rep; |
|
890 |
2589
|
891 rep = old_rep; |
|
892 old_rep = 0; |
2413
|
893 } |
|
894 |
2589
|
895 if (old_rep && --old_rep->count == 0) |
|
896 delete old_rep; |
2413
|
897 } |
|
898 else |
3203
|
899 gripe_assign_conversion_failed (type_name (), rhs.type_name ()); |
2413
|
900 } |
|
901 else |
|
902 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
903 } |
|
904 |
|
905 return (assignment_ok && ! error_state); |
|
906 } |
|
907 |
|
908 bool |
2880
|
909 octave_value::try_assignment_with_conversion (octave_value::assign_op op, |
|
910 const octave_value_list& idx, |
2413
|
911 const octave_value& rhs) |
|
912 { |
2880
|
913 bool assignment_ok = convert_and_assign (op, idx, rhs); |
2413
|
914 |
|
915 if (! (error_state || assignment_ok)) |
|
916 { |
|
917 octave_value tmp_rhs; |
2427
|
918 type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); |
2413
|
919 |
|
920 if (cf_rhs) |
3203
|
921 { |
|
922 octave_value *tmp = cf_rhs (*rhs.rep); |
|
923 |
|
924 if (tmp) |
|
925 tmp_rhs = octave_value (tmp); |
|
926 else |
|
927 { |
|
928 gripe_assign_conversion_failed (type_name (), rhs.type_name ()); |
|
929 return false; |
|
930 } |
|
931 } |
2413
|
932 else |
|
933 tmp_rhs = rhs; |
|
934 |
|
935 octave_value *old_rep = 0; |
2427
|
936 type_conv_fcn cf_this = numeric_conversion_function (); |
2413
|
937 |
|
938 if (cf_this) |
|
939 { |
|
940 old_rep = rep; |
3203
|
941 |
|
942 octave_value *tmp = cf_this (*rep); |
|
943 |
|
944 if (tmp) |
|
945 { |
|
946 rep = tmp; |
|
947 rep->count = 1; |
|
948 } |
|
949 else |
|
950 { |
|
951 gripe_assign_conversion_failed (type_name (), rhs.type_name ()); |
|
952 return false; |
|
953 } |
2413
|
954 } |
|
955 |
|
956 if (cf_this || cf_rhs) |
|
957 { |
2880
|
958 assignment_ok = try_assignment (op, idx, tmp_rhs); |
2413
|
959 |
|
960 if (! (error_state || assignment_ok)) |
2880
|
961 assignment_ok = convert_and_assign (op, idx, tmp_rhs); |
2413
|
962 } |
|
963 |
|
964 if (! assignment_ok && old_rep) |
|
965 { |
|
966 if (--rep->count == 0) |
|
967 delete rep; |
|
968 |
|
969 rep = old_rep; |
|
970 old_rep = 0; |
|
971 } |
|
972 |
|
973 if (old_rep && --old_rep->count == 0) |
|
974 delete old_rep; |
|
975 } |
|
976 |
|
977 return (assignment_ok && ! error_state); |
|
978 } |
|
979 |
|
980 bool |
2880
|
981 octave_value::try_assignment (octave_value::assign_op op, |
|
982 const octave_value_list& idx, |
2413
|
983 const octave_value& rhs) |
|
984 { |
|
985 bool retval = false; |
|
986 |
|
987 int t_lhs = type_id (); |
|
988 int t_rhs = rhs.type_id (); |
|
989 |
2880
|
990 assign_op_fcn f |
|
991 = octave_value_typeinfo::lookup_assign_op (op, t_lhs, t_rhs); |
2413
|
992 |
|
993 if (f) |
|
994 { |
|
995 f (*rep, idx, *(rhs.rep)); |
|
996 |
|
997 retval = (! error_state); |
|
998 } |
3196
|
999 else |
|
1000 { |
|
1001 f = octave_value_typeinfo::lookup_assignany_op (op, t_lhs); |
|
1002 |
|
1003 if (f) |
|
1004 { |
|
1005 f (*rep, idx, rhs); |
|
1006 |
|
1007 retval = (! error_state); |
|
1008 } |
|
1009 } |
2413
|
1010 |
|
1011 return retval; |
|
1012 } |
|
1013 |
|
1014 static void |
2376
|
1015 gripe_binary_op (const string& on, const string& tn1, const string& tn2) |
|
1016 { |
2903
|
1017 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376
|
1018 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
1019 } |
|
1020 |
3203
|
1021 static void |
|
1022 gripe_binary_op_conv (const string& on) |
|
1023 { |
|
1024 error ("type conversion failed for binary operator `%s'", on.c_str ()); |
|
1025 } |
|
1026 |
2376
|
1027 octave_value |
|
1028 do_binary_op (octave_value::binary_op op, const octave_value& v1, |
|
1029 const octave_value& v2) |
|
1030 { |
|
1031 octave_value retval; |
|
1032 |
|
1033 int t1 = v1.type_id (); |
|
1034 int t2 = v2.type_id (); |
|
1035 |
2427
|
1036 binary_op_fcn f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1037 |
|
1038 if (f) |
|
1039 retval = f (*v1.rep, *v2.rep); |
|
1040 else |
|
1041 { |
|
1042 octave_value tv1; |
2427
|
1043 type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
1044 |
|
1045 if (cf1) |
|
1046 { |
3203
|
1047 octave_value *tmp = cf1 (*v1.rep); |
|
1048 |
|
1049 if (tmp) |
|
1050 { |
|
1051 tv1 = octave_value (tmp); |
|
1052 t1 = tv1.type_id (); |
|
1053 } |
|
1054 else |
|
1055 { |
|
1056 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1057 return retval; |
|
1058 } |
2376
|
1059 } |
|
1060 else |
|
1061 tv1 = v1; |
|
1062 |
|
1063 octave_value tv2; |
2427
|
1064 type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
1065 |
|
1066 if (cf2) |
|
1067 { |
3203
|
1068 octave_value *tmp = cf2 (*v2.rep); |
|
1069 |
|
1070 if (tmp) |
|
1071 { |
|
1072 tv2 = octave_value (tmp); |
|
1073 t2 = tv2.type_id (); |
|
1074 } |
|
1075 else |
|
1076 { |
|
1077 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1078 return retval; |
|
1079 } |
2376
|
1080 } |
|
1081 else |
|
1082 tv2 = v2; |
|
1083 |
|
1084 if (cf1 || cf2) |
|
1085 { |
2427
|
1086 binary_op_fcn f |
2376
|
1087 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
|
1088 |
|
1089 if (f) |
|
1090 retval = f (*tv1.rep, *tv2.rep); |
|
1091 else |
|
1092 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1093 v1.type_name (), v2.type_name ()); |
|
1094 } |
|
1095 else |
|
1096 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1097 v1.type_name (), v2.type_name ()); |
|
1098 } |
|
1099 |
|
1100 return retval; |
|
1101 } |
|
1102 |
3203
|
1103 static void |
|
1104 gripe_unary_op (const string& on, const string& tn) |
|
1105 { |
|
1106 error ("unary operator `%s' not implemented for `%s' operands", |
|
1107 on.c_str (), tn.c_str ()); |
|
1108 } |
|
1109 |
|
1110 static void |
|
1111 gripe_unary_op_conv (const string& on) |
|
1112 { |
|
1113 error ("type conversion failed for unary operator `%s'", on.c_str ()); |
|
1114 } |
|
1115 |
|
1116 octave_value |
|
1117 do_unary_op (octave_value::unary_op op, const octave_value& v) |
|
1118 { |
|
1119 octave_value retval; |
|
1120 |
|
1121 int t = v.type_id (); |
|
1122 |
|
1123 unary_op_fcn f = octave_value_typeinfo::lookup_unary_op (op, t); |
|
1124 |
|
1125 if (f) |
|
1126 retval = f (*v.rep); |
|
1127 else |
|
1128 { |
|
1129 octave_value tv; |
|
1130 type_conv_fcn cf = v.numeric_conversion_function (); |
|
1131 |
|
1132 if (cf) |
|
1133 { |
|
1134 octave_value *tmp = cf (*v.rep); |
|
1135 |
|
1136 if (tmp) |
|
1137 { |
|
1138 tv = octave_value (tmp); |
|
1139 t = tv.type_id (); |
|
1140 |
|
1141 unary_op_fcn f = octave_value_typeinfo::lookup_unary_op (op, t); |
|
1142 |
|
1143 if (f) |
|
1144 retval = f (*tv.rep); |
|
1145 else |
|
1146 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1147 v.type_name ()); |
|
1148 } |
|
1149 else |
|
1150 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
|
1151 } |
|
1152 else |
|
1153 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1154 v.type_name ()); |
|
1155 } |
|
1156 |
|
1157 return retval; |
|
1158 } |
|
1159 |
|
1160 static void |
|
1161 gripe_unary_op_conversion_failed (const string& op, const string& tn) |
|
1162 { |
|
1163 error ("operator %s: type conversion for `%s' failed", |
|
1164 op.c_str (), tn.c_str ()); |
|
1165 } |
|
1166 |
|
1167 void |
|
1168 octave_value::do_non_const_unary_op (octave_value::unary_op op) |
|
1169 { |
|
1170 octave_value retval; |
|
1171 |
|
1172 int t = type_id (); |
|
1173 |
|
1174 non_const_unary_op_fcn f |
|
1175 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1176 |
|
1177 if (f) |
|
1178 { |
|
1179 make_unique (); |
|
1180 |
|
1181 f (*rep); |
|
1182 } |
|
1183 else |
|
1184 { |
|
1185 type_conv_fcn cf = numeric_conversion_function (); |
|
1186 |
|
1187 if (cf) |
|
1188 { |
|
1189 octave_value *tmp = cf (*rep); |
|
1190 |
|
1191 if (tmp) |
|
1192 { |
|
1193 octave_value *old_rep = rep; |
|
1194 rep = tmp; |
|
1195 rep->count = 1; |
|
1196 |
|
1197 t = type_id (); |
|
1198 |
|
1199 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1200 |
|
1201 if (f) |
|
1202 { |
|
1203 f (*rep); |
|
1204 |
|
1205 if (old_rep && --old_rep->count == 0) |
|
1206 delete old_rep; |
|
1207 } |
|
1208 else |
|
1209 { |
|
1210 if (old_rep) |
|
1211 { |
|
1212 if (--rep->count == 0) |
|
1213 delete rep; |
|
1214 |
|
1215 rep = old_rep; |
|
1216 } |
|
1217 |
|
1218 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1219 type_name ()); |
|
1220 } |
|
1221 } |
|
1222 else |
|
1223 gripe_unary_op_conversion_failed |
|
1224 (octave_value::unary_op_as_string (op), type_name ()); |
|
1225 } |
|
1226 else |
|
1227 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); |
|
1228 } |
|
1229 } |
|
1230 |
3205
|
1231 static void |
|
1232 gripe_unary_op_failed_or_no_method (const string& on, const string& tn) |
|
1233 { |
|
1234 error ("operator %s: no method, or unable to evaluate for %s operand", |
|
1235 on.c_str (), tn.c_str ()); |
|
1236 } |
|
1237 |
|
1238 void |
|
1239 octave_value::do_non_const_unary_op (octave_value::unary_op op, |
|
1240 const octave_value_list& idx) |
|
1241 { |
|
1242 // XXX FIXME XXX -- only do the following stuff if we can't find a |
|
1243 // specific function to call to handle the op= operation for the |
|
1244 // types we have. |
|
1245 |
|
1246 assign_op assop = unary_op_to_assign_op (op); |
|
1247 |
|
1248 if (! error_state) |
|
1249 assign (assop, idx, 1.0); |
|
1250 else |
|
1251 gripe_unary_op_failed_or_no_method (unary_op_as_string (op), |
|
1252 type_name ()); |
|
1253 } |
|
1254 |
2903
|
1255 // Current indentation. |
|
1256 int octave_value::curr_print_indent_level = 0; |
|
1257 |
3018
|
1258 // TRUE means we are at the beginning of a line. |
2903
|
1259 bool octave_value::beginning_of_line = true; |
|
1260 |
|
1261 // Each print() function should call this before printing anything. |
|
1262 // |
|
1263 // This doesn't need to be fast, but isn't there a better way? |
|
1264 |
|
1265 void |
|
1266 octave_value::indent (ostream& os) const |
|
1267 { |
|
1268 assert (curr_print_indent_level >= 0); |
|
1269 |
|
1270 if (beginning_of_line) |
|
1271 { |
|
1272 // XXX FIXME XXX -- do we need this? |
|
1273 // os << prefix; |
|
1274 |
|
1275 for (int i = 0; i < curr_print_indent_level; i++) |
|
1276 os << " "; |
|
1277 |
|
1278 beginning_of_line = false; |
|
1279 } |
|
1280 } |
|
1281 |
|
1282 // All print() functions should use this to print new lines. |
|
1283 |
|
1284 void |
|
1285 octave_value::newline (ostream& os) const |
|
1286 { |
|
1287 os << "\n"; |
|
1288 |
|
1289 beginning_of_line = true; |
|
1290 } |
|
1291 |
|
1292 // For ressetting print state. |
|
1293 |
|
1294 void |
|
1295 octave_value::reset (void) const |
|
1296 { |
|
1297 beginning_of_line = true; |
|
1298 curr_print_indent_level = 0; |
|
1299 } |
|
1300 |
3205
|
1301 octave_value::assign_op |
|
1302 octave_value::unary_op_to_assign_op (unary_op op) |
|
1303 { |
|
1304 assign_op binop = unknown_assign_op; |
|
1305 |
|
1306 switch (op) |
|
1307 { |
|
1308 case incr: |
|
1309 binop = add_eq; |
|
1310 break; |
|
1311 |
|
1312 case decr: |
|
1313 binop = sub_eq; |
|
1314 break; |
|
1315 |
|
1316 default: |
|
1317 { |
|
1318 string on = unary_op_as_string (op); |
|
1319 error ("operator %s: no assign operator found", on.c_str ()); |
|
1320 } |
|
1321 } |
|
1322 |
|
1323 return binop; |
|
1324 } |
|
1325 |
3204
|
1326 octave_value::binary_op |
|
1327 octave_value::op_eq_to_binary_op (assign_op op) |
|
1328 { |
|
1329 binary_op binop = unknown_binary_op; |
|
1330 |
|
1331 switch (op) |
|
1332 { |
|
1333 case add_eq: |
|
1334 binop = add; |
|
1335 break; |
|
1336 |
|
1337 case sub_eq: |
|
1338 binop = sub; |
|
1339 break; |
|
1340 |
|
1341 case mul_eq: |
|
1342 binop = mul; |
|
1343 break; |
|
1344 |
|
1345 case div_eq: |
|
1346 binop = div; |
|
1347 break; |
|
1348 |
|
1349 case ldiv_eq: |
|
1350 binop = ldiv; |
|
1351 break; |
|
1352 |
|
1353 case lshift_eq: |
|
1354 binop = lshift; |
|
1355 break; |
|
1356 |
|
1357 case rshift_eq: |
|
1358 binop = rshift; |
|
1359 break; |
|
1360 |
|
1361 case el_mul_eq: |
|
1362 binop = el_mul; |
|
1363 break; |
|
1364 |
|
1365 case el_div_eq: |
|
1366 binop = el_div; |
|
1367 break; |
|
1368 |
|
1369 case el_ldiv_eq: |
|
1370 binop = el_ldiv; |
|
1371 break; |
|
1372 |
|
1373 case el_and_eq: |
|
1374 binop = el_and; |
|
1375 break; |
|
1376 |
|
1377 case el_or_eq: |
|
1378 binop = el_or; |
|
1379 break; |
|
1380 |
|
1381 default: |
|
1382 { |
|
1383 string on = assign_op_as_string (op); |
|
1384 error ("operator %s: no binary operator found", on.c_str ()); |
|
1385 } |
|
1386 } |
|
1387 |
|
1388 return binop; |
|
1389 } |
|
1390 |
2376
|
1391 void |
|
1392 install_types (void) |
|
1393 { |
|
1394 octave_base_value::register_type (); |
|
1395 octave_scalar::register_type (); |
|
1396 octave_complex::register_type (); |
|
1397 octave_matrix::register_type (); |
|
1398 octave_complex_matrix::register_type (); |
|
1399 octave_range::register_type (); |
2825
|
1400 octave_bool::register_type (); |
|
1401 octave_bool_matrix::register_type (); |
2376
|
1402 octave_char_matrix::register_type (); |
|
1403 octave_char_matrix_str::register_type (); |
|
1404 octave_struct::register_type (); |
2903
|
1405 octave_file::register_type (); |
2880
|
1406 octave_list::register_type (); |
2376
|
1407 octave_all_va_args::register_type (); |
|
1408 octave_magic_colon::register_type (); |
2974
|
1409 octave_builtin::register_type (); |
|
1410 octave_mapper::register_type (); |
|
1411 octave_user_function::register_type (); |
2376
|
1412 } |
|
1413 |
|
1414 static int |
|
1415 do_fortran_indexing (void) |
|
1416 { |
|
1417 Vdo_fortran_indexing = check_preference ("do_fortran_indexing"); |
|
1418 |
|
1419 liboctave_dfi_flag = Vdo_fortran_indexing; |
|
1420 |
|
1421 return 0; |
|
1422 } |
|
1423 |
|
1424 static int |
|
1425 implicit_str_to_num_ok (void) |
|
1426 { |
|
1427 Vimplicit_str_to_num_ok = check_preference ("implicit_str_to_num_ok"); |
|
1428 |
|
1429 return 0; |
|
1430 } |
|
1431 |
|
1432 static int |
|
1433 ok_to_lose_imaginary_part (void) |
|
1434 { |
|
1435 Vok_to_lose_imaginary_part = check_preference ("ok_to_lose_imaginary_part"); |
|
1436 |
|
1437 return 0; |
|
1438 } |
|
1439 |
|
1440 static int |
|
1441 prefer_column_vectors (void) |
|
1442 { |
|
1443 Vprefer_column_vectors |
|
1444 = check_preference ("prefer_column_vectors"); |
|
1445 |
|
1446 liboctave_pcv_flag = Vprefer_column_vectors; |
|
1447 |
|
1448 return 0; |
|
1449 } |
|
1450 |
|
1451 static int |
|
1452 print_answer_id_name (void) |
|
1453 { |
|
1454 Vprint_answer_id_name = check_preference ("print_answer_id_name"); |
|
1455 |
|
1456 return 0; |
|
1457 } |
|
1458 |
|
1459 static int |
|
1460 propagate_empty_matrices (void) |
|
1461 { |
|
1462 Vpropagate_empty_matrices = check_preference ("propagate_empty_matrices"); |
|
1463 |
|
1464 return 0; |
|
1465 } |
|
1466 |
|
1467 static int |
|
1468 resize_on_range_error (void) |
|
1469 { |
|
1470 Vresize_on_range_error = check_preference ("resize_on_range_error"); |
|
1471 |
|
1472 liboctave_rre_flag = Vresize_on_range_error; |
|
1473 |
|
1474 return 0; |
|
1475 } |
|
1476 |
|
1477 static int |
|
1478 struct_levels_to_print (void) |
|
1479 { |
|
1480 double val; |
|
1481 if (builtin_real_scalar_variable ("struct_levels_to_print", val) |
|
1482 && ! xisnan (val)) |
|
1483 { |
|
1484 int ival = NINT (val); |
2800
|
1485 if (ival >= 0 && ival == val) |
2376
|
1486 { |
|
1487 Vstruct_levels_to_print = ival; |
|
1488 return 0; |
|
1489 } |
|
1490 } |
|
1491 gripe_invalid_value_specified ("struct_levels_to_print"); |
|
1492 return -1; |
|
1493 } |
|
1494 |
|
1495 static int |
|
1496 warn_divide_by_zero (void) |
|
1497 { |
|
1498 Vwarn_divide_by_zero = check_preference ("warn_divide_by_zero"); |
|
1499 |
|
1500 return 0; |
|
1501 } |
|
1502 |
|
1503 void |
2909
|
1504 symbols_of_ov (void) |
2376
|
1505 { |
3258
|
1506 DEFVAR (do_fortran_indexing, 0.0, do_fortran_indexing, |
2376
|
1507 "allow single indices for matrices"); |
|
1508 |
3258
|
1509 DEFVAR (implicit_str_to_num_ok, 0.0, implicit_str_to_num_ok, |
2376
|
1510 "allow implicit string to number conversion"); |
|
1511 |
3258
|
1512 DEFVAR (ok_to_lose_imaginary_part, "warn", ok_to_lose_imaginary_part, |
2376
|
1513 "silently convert from complex to real by dropping imaginary part"); |
|
1514 |
3258
|
1515 DEFVAR (prefer_column_vectors, 1.0, prefer_column_vectors, |
2376
|
1516 "prefer column/row vectors"); |
|
1517 |
3258
|
1518 DEFVAR (print_answer_id_name, 1.0, print_answer_id_name, |
2376
|
1519 "set output style to print `var_name = ...'"); |
|
1520 |
3258
|
1521 DEFVAR (propagate_empty_matrices, 1.0, propagate_empty_matrices, |
2376
|
1522 "operations on empty matrices return an empty matrix, not an error"); |
|
1523 |
3258
|
1524 DEFVAR (resize_on_range_error, 1.0, resize_on_range_error, |
2376
|
1525 "enlarge matrices on assignment"); |
|
1526 |
3258
|
1527 DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, |
2376
|
1528 "number of levels of structure elements to print"); |
|
1529 |
3258
|
1530 DEFVAR (warn_divide_by_zero, 1.0, warn_divide_by_zero, |
2957
|
1531 "if TRUE, warn about division by zero"); |
2376
|
1532 } |
|
1533 |
|
1534 /* |
|
1535 ;;; Local Variables: *** |
|
1536 ;;; mode: C++ *** |
|
1537 ;;; End: *** |
|
1538 */ |