File: | libinterp/octave-value/ov-base.cc |
Location: | line 1437, column 15 |
Description: | Value stored to 'done' is never read |
1 | /* |
2 | |
3 | Copyright (C) 1996-2013 John W. Eaton |
4 | Copyright (C) 2009-2010 VZLU Prague |
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 |
10 | Free Software Foundation; either version 3 of the License, or (at your |
11 | option) any later version. |
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 |
19 | along with Octave; see the file COPYING. If not, see |
20 | <http://www.gnu.org/licenses/>. |
21 | |
22 | */ |
23 | |
24 | #ifdef HAVE_CONFIG_H1 |
25 | #include <config.h> |
26 | #endif |
27 | |
28 | #include <iostream> |
29 | #include <limits> |
30 | |
31 | #include "lo-ieee.h" |
32 | #include "lo-mappers.h" |
33 | |
34 | #include "defun.h" |
35 | #include "gripes.h" |
36 | #include "mxarray.h" |
37 | #include "oct-map.h" |
38 | #include "oct-obj.h" |
39 | #include "oct-lvalue.h" |
40 | #include "oct-stream.h" |
41 | #include "ops.h" |
42 | #include "ov-base.h" |
43 | #include "ov-cell.h" |
44 | #include "ov-ch-mat.h" |
45 | #include "ov-complex.h" |
46 | #include "ov-cx-mat.h" |
47 | #include "ov-range.h" |
48 | #include "ov-re-mat.h" |
49 | #include "ov-scalar.h" |
50 | #include "ov-str-mat.h" |
51 | #include "ov-fcn-handle.h" |
52 | #include "parse.h" |
53 | #include "pr-output.h" |
54 | #include "utils.h" |
55 | #include "variables.h" |
56 | |
57 | builtin_type_t btyp_mixed_numeric (builtin_type_t x, builtin_type_t y) |
58 | { |
59 | builtin_type_t retval = btyp_unknown; |
60 | |
61 | if (x == btyp_bool) |
62 | x = btyp_double; |
63 | if (y == btyp_bool) |
64 | y = btyp_double; |
65 | |
66 | if (x <= btyp_float_complex && y <= btyp_float_complex) |
67 | retval = static_cast<builtin_type_t> (x | y); |
68 | else if (x <= btyp_uint64 && y <= btyp_float) |
69 | retval = x; |
70 | else if (x <= btyp_float && y <= btyp_uint64) |
71 | retval = y; |
72 | else if ((x >= btyp_int8 && x <= btyp_int64 |
73 | && y >= btyp_int8 && y <= btyp_int64) |
74 | || (x >= btyp_uint8 && x <= btyp_uint64 |
75 | && y >= btyp_uint8 && y <= btyp_uint64)) |
76 | retval = (x > y) ? x : y; |
77 | |
78 | return retval; |
79 | } |
80 | |
81 | std::string btyp_class_name[btyp_num_types] = |
82 | { |
83 | "double", "single", "double", "single", |
84 | "int8", "int16", "int32", "int64", |
85 | "uint8", "uint16", "uint32", "uint64", |
86 | "logical", "char", |
87 | "struct", "cell", "function_handle" |
88 | }; |
89 | |
90 | string_vector |
91 | get_builtin_classes (void) |
92 | { |
93 | static string_vector retval; |
94 | |
95 | if (retval.is_empty ()) |
96 | { |
97 | int n = btyp_num_types - 2; |
98 | retval = string_vector (n); |
99 | int j = 0; |
100 | for (int i = 0; i < btyp_num_types; i++) |
101 | { |
102 | builtin_type_t ityp = static_cast<builtin_type_t> (i); |
103 | if (ityp != btyp_complex && ityp != btyp_float_complex) |
104 | retval(j++) = btyp_class_name[i]; |
105 | } |
106 | } |
107 | |
108 | return retval; |
109 | } |
110 | |
111 | DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value,int octave_base_value::t_id (-1); const std::string octave_base_value ::t_name ("<unknown type>"); const std::string octave_base_value ::c_name ("unknown"); void octave_base_value::register_type ( void) { static octave_base_value exemplar; octave_value v (& exemplar, true); t_id = octave_value_typeinfo::register_type ( octave_base_value::t_name, octave_base_value::c_name, v); } |
112 | "<unknown type>", "unknown")int octave_base_value::t_id (-1); const std::string octave_base_value ::t_name ("<unknown type>"); const std::string octave_base_value ::c_name ("unknown"); void octave_base_value::register_type ( void) { static octave_base_value exemplar; octave_value v (& exemplar, true); t_id = octave_value_typeinfo::register_type ( octave_base_value::t_name, octave_base_value::c_name, v); }; |
113 | |
114 | // TRUE means to perform automatic sparse to real mutation if there |
115 | // is memory to be saved |
116 | bool Vsparse_auto_mutate = false; |
117 | |
118 | octave_base_value * |
119 | octave_base_value::empty_clone (void) const |
120 | { |
121 | return resize (dim_vector ()).clone (); |
122 | } |
123 | |
124 | octave_value |
125 | octave_base_value::squeeze (void) const |
126 | { |
127 | std::string nm = type_name (); |
128 | error ("squeeze: invalid operation for %s type", nm.c_str ()); |
129 | return octave_value (); |
130 | } |
131 | |
132 | octave_value |
133 | octave_base_value::full_value (void) const |
134 | { |
135 | gripe_wrong_type_arg ("full: invalid operation for %s type", type_name ()); |
136 | return octave_value (); |
137 | } |
138 | |
139 | Matrix |
140 | octave_base_value::size (void) |
141 | { |
142 | const dim_vector dv = dims (); |
143 | Matrix mdv (1, dv.length ()); |
144 | for (octave_idx_type i = 0; i < dv.length (); i++) |
145 | mdv(i) = dv(i); |
146 | return mdv; |
147 | } |
148 | |
149 | octave_idx_type |
150 | octave_base_value::numel (const octave_value_list& idx) |
151 | { |
152 | return dims_to_numel (dims (), idx); |
153 | } |
154 | |
155 | octave_value |
156 | octave_base_value::subsref (const std::string&, |
157 | const std::list<octave_value_list>&) |
158 | { |
159 | std::string nm = type_name (); |
160 | error ("can't perform indexing operations for %s type", nm.c_str ()); |
161 | return octave_value (); |
162 | } |
163 | |
164 | octave_value_list |
165 | octave_base_value::subsref (const std::string&, |
166 | const std::list<octave_value_list>&, int) |
167 | { |
168 | std::string nm = type_name (); |
169 | error ("can't perform indexing operations for %s type", nm.c_str ()); |
170 | return octave_value (); |
171 | } |
172 | |
173 | octave_value |
174 | octave_base_value::subsref (const std::string& type, |
175 | const std::list<octave_value_list>& idx, |
176 | bool /* auto_add */) |
177 | { |
178 | // This way we may get a more meaningful error message. |
179 | return subsref (type, idx); |
180 | } |
181 | |
182 | octave_value_list |
183 | octave_base_value::subsref (const std::string& type, |
184 | const std::list<octave_value_list>& idx, |
185 | int nargout, |
186 | const std::list<octave_lvalue> *) |
187 | { |
188 | // Fall back to call without passing lvalue list. |
189 | return subsref (type, idx, nargout); |
190 | } |
191 | |
192 | octave_value |
193 | octave_base_value::do_index_op (const octave_value_list&, bool) |
194 | { |
195 | std::string nm = type_name (); |
196 | error ("can't perform indexing operations for %s type", nm.c_str ()); |
197 | return octave_value (); |
198 | } |
199 | |
200 | octave_value_list |
201 | octave_base_value::do_multi_index_op (int, const octave_value_list&) |
202 | { |
203 | std::string nm = type_name (); |
204 | error ("can't perform indexing operations for %s type", nm.c_str ()); |
205 | return octave_value (); |
206 | } |
207 | |
208 | octave_value_list |
209 | octave_base_value::do_multi_index_op (int nargout, const octave_value_list& idx, |
210 | const std::list<octave_lvalue> *) |
211 | { |
212 | // Fall back. |
213 | return do_multi_index_op (nargout, idx); |
214 | } |
215 | |
216 | idx_vector |
217 | octave_base_value::index_vector (void) const |
218 | { |
219 | std::string nm = type_name (); |
220 | error ("%s type invalid as index value", nm.c_str ()); |
221 | return idx_vector (); |
222 | } |
223 | |
224 | octave_value |
225 | octave_base_value::subsasgn (const std::string& type, |
226 | const std::list<octave_value_list>& idx, |
227 | const octave_value& rhs) |
228 | { |
229 | octave_value retval; |
230 | |
231 | if (is_defined ()) |
232 | { |
233 | if (is_numeric_type ()) |
234 | { |
235 | switch (type[0]) |
236 | { |
237 | case '(': |
238 | { |
239 | if (type.length () == 1) |
240 | retval = numeric_assign (type, idx, rhs); |
241 | else if (is_empty ()) |
242 | { |
243 | // Allow conversion of empty matrix to some other |
244 | // type in cases like |
245 | // |
246 | // x = []; x(i).f = rhs |
247 | |
248 | octave_value tmp = octave_value::empty_conv (type, rhs); |
249 | |
250 | retval = tmp.subsasgn (type, idx, rhs); |
251 | } |
252 | else |
253 | { |
254 | std::string nm = type_name (); |
255 | error ("in indexed assignment of %s, last rhs index must be ()", |
256 | nm.c_str ()); |
257 | } |
258 | } |
259 | break; |
260 | |
261 | case '{': |
262 | case '.': |
263 | { |
264 | std::string nm = type_name (); |
265 | error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
266 | } |
267 | break; |
268 | |
269 | default: |
270 | panic_impossible ()panic ("impossible state reached in file '%s' at line %d", "octave-value/ov-base.cc" , 270); |
271 | } |
272 | } |
273 | else |
274 | { |
275 | std::string nm = type_name (); |
276 | error ("can't perform indexed assignment for %s type", nm.c_str ()); |
277 | } |
278 | } |
279 | else |
280 | { |
281 | // Create new object of appropriate type for given index and rhs |
282 | // types and then call undef_subsasgn for that object. |
283 | |
284 | octave_value tmp = octave_value::empty_conv (type, rhs); |
285 | |
286 | retval = tmp.undef_subsasgn (type, idx, rhs); |
287 | } |
288 | |
289 | return retval; |
290 | } |
291 | |
292 | octave_value |
293 | octave_base_value::undef_subsasgn (const std::string& type, |
294 | const std::list<octave_value_list>& idx, |
295 | const octave_value& rhs) |
296 | { |
297 | // In most cases, undef_subsasgn is handled the sams as subsasgn. One |
298 | // exception is octave_class objects. |
299 | |
300 | return subsasgn (type, idx, rhs); |
301 | } |
302 | |
303 | octave_idx_type |
304 | octave_base_value::nnz (void) const |
305 | { |
306 | gripe_wrong_type_arg ("octave_base_value::nnz ()", type_name ()); |
307 | return -1; |
308 | } |
309 | |
310 | octave_idx_type |
311 | octave_base_value::nzmax (void) const |
312 | { |
313 | return numel (); |
314 | } |
315 | |
316 | octave_idx_type |
317 | octave_base_value::nfields (void) const |
318 | { |
319 | gripe_wrong_type_arg ("octave_base_value::nfields ()", type_name ()); |
320 | return -1; |
321 | } |
322 | |
323 | octave_value |
324 | octave_base_value::reshape (const dim_vector&) const |
325 | { |
326 | gripe_wrong_type_arg ("octave_base_value::reshape ()", type_name ()); |
327 | return octave_value (); |
328 | } |
329 | |
330 | octave_value |
331 | octave_base_value::permute (const Array<int>&, bool) const |
332 | { |
333 | gripe_wrong_type_arg ("octave_base_value::permute ()", type_name ()); |
334 | return octave_value (); |
335 | } |
336 | |
337 | octave_value |
338 | octave_base_value::resize (const dim_vector&, bool) const |
339 | { |
340 | gripe_wrong_type_arg ("octave_base_value::resize ()", type_name ()); |
341 | return octave_value (); |
342 | } |
343 | |
344 | MatrixType |
345 | octave_base_value::matrix_type (void) const |
346 | { |
347 | gripe_wrong_type_arg ("octave_base_value::matrix_type ()", type_name ()); |
348 | return MatrixType (); |
349 | } |
350 | |
351 | MatrixType |
352 | octave_base_value::matrix_type (const MatrixType&) const |
353 | { |
354 | gripe_wrong_type_arg ("octave_base_value::matrix_type ()", type_name ()); |
355 | return MatrixType (); |
356 | } |
357 | |
358 | octave_value |
359 | octave_base_value::all (int) const |
360 | { |
361 | return 0.0; |
362 | } |
363 | |
364 | octave_value |
365 | octave_base_value::any (int) const |
366 | { |
367 | return 0.0; |
368 | } |
369 | |
370 | octave_value |
371 | octave_base_value::convert_to_str (bool pad, bool force, char type) const |
372 | { |
373 | octave_value retval = convert_to_str_internal (pad, force, type); |
374 | |
375 | if (! force && is_numeric_type ()) |
376 | gripe_implicit_conversion ("Octave:num-to-str", |
377 | type_name (), retval.type_name ()); |
378 | |
379 | return retval; |
380 | } |
381 | |
382 | octave_value |
383 | octave_base_value::convert_to_str_internal (bool, bool, char) const |
384 | { |
385 | gripe_wrong_type_arg ("octave_base_value::convert_to_str_internal ()", |
386 | type_name ()); |
387 | return octave_value (); |
388 | } |
389 | |
390 | void |
391 | octave_base_value::convert_to_row_or_column_vector (void) |
392 | { |
393 | gripe_wrong_type_arg |
394 | ("octave_base_value::convert_to_row_or_column_vector ()", |
395 | type_name ()); |
396 | } |
397 | |
398 | void |
399 | octave_base_value::print (std::ostream&, bool) const |
400 | { |
401 | gripe_wrong_type_arg ("octave_base_value::print ()", type_name ()); |
402 | } |
403 | |
404 | void |
405 | octave_base_value::print_raw (std::ostream&, bool) const |
406 | { |
407 | gripe_wrong_type_arg ("octave_base_value::print_raw ()", type_name ()); |
408 | } |
409 | |
410 | bool |
411 | octave_base_value::print_name_tag (std::ostream& os, |
412 | const std::string& name) const |
413 | { |
414 | bool retval = false; |
415 | |
416 | indent (os); |
417 | |
418 | if (print_as_scalar ()) |
419 | os << name << " = "; |
420 | else |
421 | { |
422 | os << name << " ="; |
423 | newline (os); |
424 | if (! Vcompact_format) |
425 | newline (os); |
426 | |
427 | retval = true; |
428 | } |
429 | |
430 | return retval; |
431 | } |
432 | |
433 | void |
434 | octave_base_value::print_with_name (std::ostream& output_buf, |
435 | const std::string& name, |
436 | bool print_padding) |
437 | { |
438 | bool pad_after = print_name_tag (output_buf, name); |
439 | |
440 | print (output_buf); |
441 | |
442 | if (print_padding && pad_after && ! Vcompact_format) |
443 | newline (output_buf); |
444 | } |
445 | |
446 | void |
447 | octave_base_value::print_info (std::ostream& os, |
448 | const std::string& /* prefix */) const |
449 | { |
450 | os << "no info for type: " << type_name () << "\n"; |
451 | } |
452 | |
453 | #define INT_CONV_METHOD(T, F)T octave_base_value:: F_value (bool require_int, bool frc_str_conv ) const { T retval = 0; double d = double_value (frc_str_conv ); if (! error_state) { if (require_int && D_NINT (d) != d) error_with_cfn ("conversion of %g to " "T" " value failed" , d); else if (d < std::numeric_limits<T>::min ()) retval = std::numeric_limits<T>::min (); else if (d > std:: numeric_limits<T>::max ()) retval = std::numeric_limits <T>::max (); else retval = static_cast<T> (::fix ( d)); } else gripe_wrong_type_arg ("octave_base_value::" "F" "_value ()" , type_name ()); return retval; } \ |
454 | T \ |
455 | octave_base_value::F ## _value (bool require_int, bool frc_str_conv) const \ |
456 | { \ |
457 | T retval = 0; \ |
458 | \ |
459 | double d = double_value (frc_str_conv); \ |
460 | \ |
461 | if (! error_state) \ |
462 | { \ |
463 | if (require_int && D_NINT (d) != d) \ |
464 | error_with_cfn ("conversion of %g to " #T " value failed", d); \ |
465 | else if (d < std::numeric_limits<T>::min ()) \ |
466 | retval = std::numeric_limits<T>::min (); \ |
467 | else if (d > std::numeric_limits<T>::max ()) \ |
468 | retval = std::numeric_limits<T>::max (); \ |
469 | else \ |
470 | retval = static_cast<T> (::fix (d)); \ |
471 | } \ |
472 | else \ |
473 | gripe_wrong_type_arg ("octave_base_value::" #F "_value ()", \ |
474 | type_name ()); \ |
475 | \ |
476 | return retval; \ |
477 | } |
478 | |
479 | INT_CONV_METHOD (short int, short)short int octave_base_value:: short_value (bool require_int, bool frc_str_conv) const { short int retval = 0; double d = double_value (frc_str_conv); if (! error_state) { if (require_int && D_NINT (d) != d) error_with_cfn ("conversion of %g to " "short int" " value failed", d); else if (d < std::numeric_limits< short int>::min ()) retval = std::numeric_limits<short int >::min (); else if (d > std::numeric_limits<short int >::max ()) retval = std::numeric_limits<short int>:: max (); else retval = static_cast<short int> (::fix (d) ); } else gripe_wrong_type_arg ("octave_base_value::" "short" "_value ()", type_name ()); return retval; } |
480 | INT_CONV_METHOD (unsigned short int, ushort)unsigned short int octave_base_value:: ushort_value (bool require_int , bool frc_str_conv) const { unsigned short int retval = 0; double d = double_value (frc_str_conv); if (! error_state) { if (require_int && D_NINT (d) != d) error_with_cfn ("conversion of %g to " "unsigned short int" " value failed", d); else if (d < std ::numeric_limits<unsigned short int>::min ()) retval = std ::numeric_limits<unsigned short int>::min (); else if ( d > std::numeric_limits<unsigned short int>::max ()) retval = std::numeric_limits<unsigned short int>::max ( ); else retval = static_cast<unsigned short int> (::fix (d)); } else gripe_wrong_type_arg ("octave_base_value::" "ushort" "_value ()", type_name ()); return retval; } |
481 | |
482 | INT_CONV_METHOD (int, int)int octave_base_value:: int_value (bool require_int, bool frc_str_conv ) const { int retval = 0; double d = double_value (frc_str_conv ); if (! error_state) { if (require_int && D_NINT (d) != d) error_with_cfn ("conversion of %g to " "int" " value failed" , d); else if (d < std::numeric_limits<int>::min ()) retval = std::numeric_limits<int>::min (); else if (d > std::numeric_limits<int>::max ()) retval = std::numeric_limits <int>::max (); else retval = static_cast<int> (:: fix (d)); } else gripe_wrong_type_arg ("octave_base_value::" "int" "_value ()", type_name ()); return retval; } |
483 | INT_CONV_METHOD (unsigned int, uint)unsigned int octave_base_value:: uint_value (bool require_int , bool frc_str_conv) const { unsigned int retval = 0; double d = double_value (frc_str_conv); if (! error_state) { if (require_int && D_NINT (d) != d) error_with_cfn ("conversion of %g to " "unsigned int" " value failed", d); else if (d < std::numeric_limits <unsigned int>::min ()) retval = std::numeric_limits< unsigned int>::min (); else if (d > std::numeric_limits <unsigned int>::max ()) retval = std::numeric_limits< unsigned int>::max (); else retval = static_cast<unsigned int> (::fix (d)); } else gripe_wrong_type_arg ("octave_base_value::" "uint" "_value ()", type_name ()); return retval; } |
484 | |
485 | INT_CONV_METHOD (long int, long)long int octave_base_value:: long_value (bool require_int, bool frc_str_conv) const { long int retval = 0; double d = double_value (frc_str_conv); if (! error_state) { if (require_int && D_NINT (d) != d) error_with_cfn ("conversion of %g to " "long int" " value failed", d); else if (d < std::numeric_limits< long int>::min ()) retval = std::numeric_limits<long int >::min (); else if (d > std::numeric_limits<long int >::max ()) retval = std::numeric_limits<long int>::max (); else retval = static_cast<long int> (::fix (d)); } else gripe_wrong_type_arg ("octave_base_value::" "long" "_value ()" , type_name ()); return retval; } |
486 | INT_CONV_METHOD (unsigned long int, ulong)unsigned long int octave_base_value:: ulong_value (bool require_int , bool frc_str_conv) const { unsigned long int retval = 0; double d = double_value (frc_str_conv); if (! error_state) { if (require_int && D_NINT (d) != d) error_with_cfn ("conversion of %g to " "unsigned long int" " value failed", d); else if (d < std ::numeric_limits<unsigned long int>::min ()) retval = std ::numeric_limits<unsigned long int>::min (); else if (d > std::numeric_limits<unsigned long int>::max ()) retval = std::numeric_limits<unsigned long int>::max (); else retval = static_cast<unsigned long int> (::fix (d)); } else gripe_wrong_type_arg ("octave_base_value::" "ulong" "_value ()" , type_name ()); return retval; } |
487 | |
488 | INT_CONV_METHOD (int64_t, int64)int64_t octave_base_value:: int64_value (bool require_int, bool frc_str_conv) const { int64_t retval = 0; double d = double_value (frc_str_conv); if (! error_state) { if (require_int && D_NINT (d) != d) error_with_cfn ("conversion of %g to " "int64_t" " value failed", d); else if (d < std::numeric_limits< int64_t>::min ()) retval = std::numeric_limits<int64_t> ::min (); else if (d > std::numeric_limits<int64_t>:: max ()) retval = std::numeric_limits<int64_t>::max (); else retval = static_cast<int64_t> (::fix (d)); } else gripe_wrong_type_arg ("octave_base_value::" "int64" "_value ()", type_name ()); return retval; } |
489 | INT_CONV_METHOD (uint64_t, uint64)uint64_t octave_base_value:: uint64_value (bool require_int, bool frc_str_conv) const { uint64_t retval = 0; double d = double_value (frc_str_conv); if (! error_state) { if (require_int && D_NINT (d) != d) error_with_cfn ("conversion of %g to " "uint64_t" " value failed", d); else if (d < std::numeric_limits< uint64_t>::min ()) retval = std::numeric_limits<uint64_t >::min (); else if (d > std::numeric_limits<uint64_t >::max ()) retval = std::numeric_limits<uint64_t>::max (); else retval = static_cast<uint64_t> (::fix (d)); } else gripe_wrong_type_arg ("octave_base_value::" "uint64" "_value ()" , type_name ()); return retval; } |
490 | |
491 | int |
492 | octave_base_value::nint_value (bool frc_str_conv) const |
493 | { |
494 | int retval = 0; |
495 | |
496 | double d = double_value (frc_str_conv); |
497 | |
498 | if (! error_state) |
499 | { |
500 | if (xisnan (d)) |
501 | { |
502 | error ("conversion of NaN to integer value failed"); |
503 | return retval; |
504 | } |
505 | |
506 | retval = static_cast<int> (::fix (d)); |
507 | } |
508 | else |
509 | gripe_wrong_type_arg ("octave_base_value::nint_value ()", type_name ()); |
510 | |
511 | return retval; |
512 | } |
513 | |
514 | double |
515 | octave_base_value::double_value (bool) const |
516 | { |
517 | double retval = lo_ieee_nan_value (); |
518 | gripe_wrong_type_arg ("octave_base_value::double_value ()", type_name ()); |
519 | return retval; |
520 | } |
521 | |
522 | float |
523 | octave_base_value::float_value (bool) const |
524 | { |
525 | float retval = lo_ieee_float_nan_value (); |
526 | gripe_wrong_type_arg ("octave_base_value::float_value ()", type_name ()); |
527 | return retval; |
528 | } |
529 | |
530 | Cell |
531 | octave_base_value::cell_value () const |
532 | { |
533 | Cell retval; |
534 | gripe_wrong_type_arg ("octave_base_value::cell_value()", type_name ()); |
535 | return retval; |
536 | } |
537 | |
538 | Matrix |
539 | octave_base_value::matrix_value (bool) const |
540 | { |
541 | Matrix retval; |
542 | gripe_wrong_type_arg ("octave_base_value::matrix_value()", type_name ()); |
543 | return retval; |
544 | } |
545 | |
546 | FloatMatrix |
547 | octave_base_value::float_matrix_value (bool) const |
548 | { |
549 | FloatMatrix retval; |
550 | gripe_wrong_type_arg ("octave_base_value::float_matrix_value()", |
551 | type_name ()); |
552 | return retval; |
553 | } |
554 | |
555 | NDArray |
556 | octave_base_value::array_value (bool) const |
557 | { |
558 | FloatNDArray retval; |
559 | gripe_wrong_type_arg ("octave_base_value::array_value()", type_name ()); |
560 | return retval; |
561 | } |
562 | |
563 | FloatNDArray |
564 | octave_base_value::float_array_value (bool) const |
565 | { |
566 | FloatNDArray retval; |
567 | gripe_wrong_type_arg ("octave_base_value::float_array_value()", type_name ()); |
568 | return retval; |
569 | } |
570 | |
571 | Complex |
572 | octave_base_value::complex_value (bool) const |
573 | { |
574 | double tmp = lo_ieee_nan_value (); |
575 | Complex retval (tmp, tmp); |
576 | gripe_wrong_type_arg ("octave_base_value::complex_value()", type_name ()); |
577 | return retval; |
578 | } |
579 | |
580 | FloatComplex |
581 | octave_base_value::float_complex_value (bool) const |
582 | { |
583 | float tmp = lo_ieee_float_nan_value (); |
584 | FloatComplex retval (tmp, tmp); |
585 | gripe_wrong_type_arg ("octave_base_value::float_complex_value()", |
586 | type_name ()); |
587 | return retval; |
588 | } |
589 | |
590 | ComplexMatrix |
591 | octave_base_value::complex_matrix_value (bool) const |
592 | { |
593 | ComplexMatrix retval; |
594 | gripe_wrong_type_arg ("octave_base_value::complex_matrix_value()", |
595 | type_name ()); |
596 | return retval; |
597 | } |
598 | |
599 | FloatComplexMatrix |
600 | octave_base_value::float_complex_matrix_value (bool) const |
601 | { |
602 | FloatComplexMatrix retval; |
603 | gripe_wrong_type_arg ("octave_base_value::float_complex_matrix_value()", |
604 | type_name ()); |
605 | return retval; |
606 | } |
607 | |
608 | ComplexNDArray |
609 | octave_base_value::complex_array_value (bool) const |
610 | { |
611 | ComplexNDArray retval; |
612 | gripe_wrong_type_arg ("octave_base_value::complex_array_value()", |
613 | type_name ()); |
614 | return retval; |
615 | } |
616 | |
617 | FloatComplexNDArray |
618 | octave_base_value::float_complex_array_value (bool) const |
619 | { |
620 | FloatComplexNDArray retval; |
621 | gripe_wrong_type_arg ("octave_base_value::float_complex_array_value()", |
622 | type_name ()); |
623 | return retval; |
624 | } |
625 | |
626 | bool |
627 | octave_base_value::bool_value (bool) const |
628 | { |
629 | bool retval = false; |
630 | gripe_wrong_type_arg ("octave_base_value::bool_value()", type_name ()); |
631 | return retval; |
632 | } |
633 | |
634 | boolMatrix |
635 | octave_base_value::bool_matrix_value (bool) const |
636 | { |
637 | boolMatrix retval; |
638 | gripe_wrong_type_arg ("octave_base_value::bool_matrix_value()", |
639 | type_name ()); |
640 | return retval; |
641 | } |
642 | |
643 | boolNDArray |
644 | octave_base_value::bool_array_value (bool) const |
645 | { |
646 | boolNDArray retval; |
647 | gripe_wrong_type_arg ("octave_base_value::bool_array_value()", |
648 | type_name ()); |
649 | return retval; |
650 | } |
651 | |
652 | charMatrix |
653 | octave_base_value::char_matrix_value (bool force) const |
654 | { |
655 | charMatrix retval; |
656 | |
657 | octave_value tmp = convert_to_str (false, force); |
658 | |
659 | if (! error_state) |
660 | retval = tmp.char_matrix_value (); |
661 | |
662 | return retval; |
663 | } |
664 | |
665 | charNDArray |
666 | octave_base_value::char_array_value (bool) const |
667 | { |
668 | charNDArray retval; |
669 | gripe_wrong_type_arg ("octave_base_value::char_array_value()", |
670 | type_name ()); |
671 | return retval; |
672 | } |
673 | |
674 | SparseMatrix |
675 | octave_base_value::sparse_matrix_value (bool) const |
676 | { |
677 | SparseMatrix retval; |
678 | gripe_wrong_type_arg ("octave_base_value::sparse_matrix_value()", |
679 | type_name ()); |
680 | return retval; |
681 | } |
682 | |
683 | SparseComplexMatrix |
684 | octave_base_value::sparse_complex_matrix_value (bool) const |
685 | { |
686 | SparseComplexMatrix retval; |
687 | gripe_wrong_type_arg ("octave_base_value::sparse_complex_matrix_value()", |
688 | type_name ()); |
689 | return retval; |
690 | } |
691 | |
692 | SparseBoolMatrix |
693 | octave_base_value::sparse_bool_matrix_value (bool) const |
694 | { |
695 | SparseBoolMatrix retval; |
696 | gripe_wrong_type_arg ("octave_base_value::sparse_bool_matrix_value()", |
697 | type_name ()); |
698 | return retval; |
699 | } |
700 | |
701 | DiagMatrix |
702 | octave_base_value::diag_matrix_value (bool) const |
703 | { |
704 | DiagMatrix retval; |
705 | gripe_wrong_type_arg ("octave_base_value::diag_matrix_value()", type_name ()); |
706 | return retval; |
707 | } |
708 | |
709 | FloatDiagMatrix |
710 | octave_base_value::float_diag_matrix_value (bool) const |
711 | { |
712 | FloatDiagMatrix retval; |
713 | gripe_wrong_type_arg ("octave_base_value::float_diag_matrix_value()", |
714 | type_name ()); |
715 | return retval; |
716 | } |
717 | |
718 | ComplexDiagMatrix |
719 | octave_base_value::complex_diag_matrix_value (bool) const |
720 | { |
721 | ComplexDiagMatrix retval; |
722 | gripe_wrong_type_arg ("octave_base_value::complex_diag_matrix_value()", |
723 | type_name ()); |
724 | return retval; |
725 | } |
726 | |
727 | FloatComplexDiagMatrix |
728 | octave_base_value::float_complex_diag_matrix_value (bool) const |
729 | { |
730 | FloatComplexDiagMatrix retval; |
731 | gripe_wrong_type_arg ("octave_base_value::float_complex_diag_matrix_value()", |
732 | type_name ()); |
733 | return retval; |
734 | } |
735 | |
736 | PermMatrix |
737 | octave_base_value::perm_matrix_value (void) const |
738 | { |
739 | PermMatrix retval; |
740 | gripe_wrong_type_arg ("octave_base_value::perm_matrix_value()", type_name ()); |
741 | return retval; |
742 | } |
743 | |
744 | octave_int8 |
745 | octave_base_value::int8_scalar_value (void) const |
746 | { |
747 | octave_int8 retval; |
748 | gripe_wrong_type_arg ("octave_base_value::int8_scalar_value()", |
749 | type_name ()); |
750 | return retval; |
751 | } |
752 | |
753 | octave_int16 |
754 | octave_base_value::int16_scalar_value (void) const |
755 | { |
756 | octave_int16 retval; |
757 | gripe_wrong_type_arg ("octave_base_value::int16_scalar_value()", |
758 | type_name ()); |
759 | return retval; |
760 | } |
761 | |
762 | octave_int32 |
763 | octave_base_value::int32_scalar_value (void) const |
764 | { |
765 | octave_int32 retval; |
766 | gripe_wrong_type_arg ("octave_base_value::int32_scalar_value()", |
767 | type_name ()); |
768 | return retval; |
769 | } |
770 | |
771 | octave_int64 |
772 | octave_base_value::int64_scalar_value (void) const |
773 | { |
774 | octave_int64 retval; |
775 | gripe_wrong_type_arg ("octave_base_value::int64_scalar_value()", |
776 | type_name ()); |
777 | return retval; |
778 | } |
779 | |
780 | octave_uint8 |
781 | octave_base_value::uint8_scalar_value (void) const |
782 | { |
783 | octave_uint8 retval; |
784 | gripe_wrong_type_arg ("octave_base_value::uint8_scalar_value()", |
785 | type_name ()); |
786 | return retval; |
787 | } |
788 | |
789 | octave_uint16 |
790 | octave_base_value::uint16_scalar_value (void) const |
791 | { |
792 | octave_uint16 retval; |
793 | gripe_wrong_type_arg ("octave_base_value::uint16_scalar_value()", |
794 | type_name ()); |
795 | return retval; |
796 | } |
797 | |
798 | octave_uint32 |
799 | octave_base_value::uint32_scalar_value (void) const |
800 | { |
801 | octave_uint32 retval; |
802 | gripe_wrong_type_arg ("octave_base_value::uint32_scalar_value()", |
803 | type_name ()); |
804 | return retval; |
805 | } |
806 | |
807 | octave_uint64 |
808 | octave_base_value::uint64_scalar_value (void) const |
809 | { |
810 | octave_uint64 retval; |
811 | gripe_wrong_type_arg ("octave_base_value::uint64_scalar_value()", |
812 | type_name ()); |
813 | return retval; |
814 | } |
815 | |
816 | int8NDArray |
817 | octave_base_value::int8_array_value (void) const |
818 | { |
819 | int8NDArray retval; |
820 | gripe_wrong_type_arg ("octave_base_value::int8_array_value()", |
821 | type_name ()); |
822 | return retval; |
823 | } |
824 | |
825 | int16NDArray |
826 | octave_base_value::int16_array_value (void) const |
827 | { |
828 | int16NDArray retval; |
829 | gripe_wrong_type_arg ("octave_base_value::int16_array_value()", |
830 | type_name ()); |
831 | return retval; |
832 | } |
833 | |
834 | int32NDArray |
835 | octave_base_value::int32_array_value (void) const |
836 | { |
837 | int32NDArray retval; |
838 | gripe_wrong_type_arg ("octave_base_value::int32_array_value()", |
839 | type_name ()); |
840 | return retval; |
841 | } |
842 | |
843 | int64NDArray |
844 | octave_base_value::int64_array_value (void) const |
845 | { |
846 | int64NDArray retval; |
847 | gripe_wrong_type_arg ("octave_base_value::int64_array_value()", |
848 | type_name ()); |
849 | return retval; |
850 | } |
851 | |
852 | uint8NDArray |
853 | octave_base_value::uint8_array_value (void) const |
854 | { |
855 | uint8NDArray retval; |
856 | gripe_wrong_type_arg ("octave_base_value::uint8_array_value()", |
857 | type_name ()); |
858 | return retval; |
859 | } |
860 | |
861 | uint16NDArray |
862 | octave_base_value::uint16_array_value (void) const |
863 | { |
864 | uint16NDArray retval; |
865 | gripe_wrong_type_arg ("octave_base_value::uint16_array_value()", |
866 | type_name ()); |
867 | return retval; |
868 | } |
869 | |
870 | uint32NDArray |
871 | octave_base_value::uint32_array_value (void) const |
872 | { |
873 | uint32NDArray retval; |
874 | gripe_wrong_type_arg ("octave_base_value::uint32_array_value()", |
875 | type_name ()); |
876 | return retval; |
877 | } |
878 | |
879 | uint64NDArray |
880 | octave_base_value::uint64_array_value (void) const |
881 | { |
882 | uint64NDArray retval; |
883 | gripe_wrong_type_arg ("octave_base_value::uint64_array_value()", |
884 | type_name ()); |
885 | return retval; |
886 | } |
887 | |
888 | string_vector |
889 | octave_base_value::all_strings (bool pad) const |
890 | { |
891 | string_vector retval; |
892 | |
893 | octave_value tmp = convert_to_str (pad, true); |
894 | |
895 | if (! error_state) |
896 | retval = tmp.all_strings (); |
897 | |
898 | return retval; |
899 | } |
900 | |
901 | std::string |
902 | octave_base_value::string_value (bool force) const |
903 | { |
904 | std::string retval; |
905 | |
906 | octave_value tmp = convert_to_str (force); |
907 | |
908 | if (! error_state) |
909 | retval = tmp.string_value (); |
910 | |
911 | return retval; |
912 | } |
913 | |
914 | Array<std::string> |
915 | octave_base_value::cellstr_value (void) const |
916 | { |
917 | Array<std::string> retval; |
918 | gripe_wrong_type_arg ("octave_base_value::cellstry_value()", |
919 | type_name ()); |
920 | return retval; |
921 | } |
922 | |
923 | Range |
924 | octave_base_value::range_value (void) const |
925 | { |
926 | Range retval; |
927 | gripe_wrong_type_arg ("octave_base_value::range_value()", type_name ()); |
928 | return retval; |
929 | } |
930 | |
931 | octave_map |
932 | octave_base_value::map_value (void) const |
933 | { |
934 | octave_map retval; |
935 | gripe_wrong_type_arg ("octave_base_value::map_value()", type_name ()); |
936 | return retval; |
937 | } |
938 | |
939 | octave_scalar_map |
940 | octave_base_value::scalar_map_value (void) const |
941 | { |
942 | octave_map tmp = map_value (); |
943 | |
944 | if (tmp.numel () == 1) |
945 | return tmp.checkelem (0); |
946 | else |
947 | { |
948 | if (! error_state) |
949 | error ("invalid conversion of multi-dimensional struct to scalar struct"); |
950 | |
951 | return octave_scalar_map (); |
952 | } |
953 | } |
954 | |
955 | string_vector |
956 | octave_base_value::map_keys (void) const |
957 | { |
958 | string_vector retval; |
959 | gripe_wrong_type_arg ("octave_base_value::map_keys()", type_name ()); |
960 | return retval; |
961 | } |
962 | |
963 | size_t |
964 | octave_base_value::nparents (void) const |
965 | { |
966 | size_t retval = 0; |
967 | gripe_wrong_type_arg ("octave_base_value::nparents()", type_name ()); |
968 | return retval; |
969 | } |
970 | |
971 | std::list<std::string> |
972 | octave_base_value::parent_class_name_list (void) const |
973 | { |
974 | std::list<std::string> retval; |
975 | gripe_wrong_type_arg ("octave_base_value::parent_class_name_list()", |
976 | type_name ()); |
977 | return retval; |
978 | } |
979 | |
980 | string_vector |
981 | octave_base_value::parent_class_names (void) const |
982 | { |
983 | string_vector retval; |
984 | gripe_wrong_type_arg ("octave_base_value::parent_class_names()", |
985 | type_name ()); |
986 | return retval; |
987 | } |
988 | |
989 | octave_function * |
990 | octave_base_value::function_value (bool silent) |
991 | { |
992 | octave_function *retval = 0; |
993 | |
994 | if (! silent) |
995 | gripe_wrong_type_arg ("octave_base_value::function_value()", |
996 | type_name ()); |
997 | return retval; |
998 | } |
999 | |
1000 | octave_user_function * |
1001 | octave_base_value::user_function_value (bool silent) |
1002 | { |
1003 | octave_user_function *retval = 0; |
1004 | |
1005 | if (! silent) |
1006 | gripe_wrong_type_arg ("octave_base_value::user_function_value()", |
1007 | type_name ()); |
1008 | return retval; |
1009 | } |
1010 | |
1011 | octave_user_script * |
1012 | octave_base_value::user_script_value (bool silent) |
1013 | { |
1014 | octave_user_script *retval = 0; |
1015 | |
1016 | if (! silent) |
1017 | gripe_wrong_type_arg ("octave_base_value::user_script_value()", |
1018 | type_name ()); |
1019 | return retval; |
1020 | } |
1021 | |
1022 | octave_user_code * |
1023 | octave_base_value::user_code_value (bool silent) |
1024 | { |
1025 | octave_user_code *retval = 0; |
1026 | |
1027 | if (! silent) |
1028 | gripe_wrong_type_arg ("octave_base_value::user_code_value()", |
1029 | type_name ()); |
1030 | return retval; |
1031 | } |
1032 | |
1033 | octave_fcn_handle * |
1034 | octave_base_value::fcn_handle_value (bool silent) |
1035 | { |
1036 | octave_fcn_handle *retval = 0; |
1037 | |
1038 | if (! silent) |
1039 | gripe_wrong_type_arg ("octave_base_value::fcn_handle_value()", |
1040 | type_name ()); |
1041 | return retval; |
1042 | } |
1043 | |
1044 | octave_fcn_inline * |
1045 | octave_base_value::fcn_inline_value (bool silent) |
1046 | { |
1047 | octave_fcn_inline *retval = 0; |
1048 | |
1049 | if (! silent) |
1050 | gripe_wrong_type_arg ("octave_base_value::fcn_inline_value()", |
1051 | type_name ()); |
1052 | return retval; |
1053 | } |
1054 | |
1055 | octave_value_list |
1056 | octave_base_value::list_value (void) const |
1057 | { |
1058 | octave_value_list retval; |
1059 | gripe_wrong_type_arg ("octave_base_value::list_value()", type_name ()); |
1060 | return retval; |
1061 | } |
1062 | |
1063 | bool |
1064 | octave_base_value::save_ascii (std::ostream&) |
1065 | { |
1066 | gripe_wrong_type_arg ("octave_base_value::save_ascii()", type_name ()); |
1067 | return false; |
1068 | } |
1069 | |
1070 | bool |
1071 | octave_base_value::load_ascii (std::istream&) |
1072 | { |
1073 | gripe_wrong_type_arg ("octave_base_value::load_ascii()", type_name ()); |
1074 | return false; |
1075 | } |
1076 | |
1077 | bool |
1078 | octave_base_value::save_binary (std::ostream&, bool&) |
1079 | { |
1080 | gripe_wrong_type_arg ("octave_base_value::save_binary()", type_name ()); |
1081 | return false; |
1082 | } |
1083 | |
1084 | bool |
1085 | octave_base_value::load_binary (std::istream&, bool, |
1086 | oct_mach_info::float_format) |
1087 | { |
1088 | gripe_wrong_type_arg ("octave_base_value::load_binary()", type_name ()); |
1089 | return false; |
1090 | } |
1091 | |
1092 | #if defined (HAVE_HDF51) |
1093 | |
1094 | bool |
1095 | octave_base_value::save_hdf5 (hid_t, const char *, bool) |
1096 | { |
1097 | gripe_wrong_type_arg ("octave_base_value::save_binary()", type_name ()); |
1098 | |
1099 | return false; |
1100 | } |
1101 | |
1102 | bool |
1103 | octave_base_value::load_hdf5 (hid_t, const char *) |
1104 | { |
1105 | gripe_wrong_type_arg ("octave_base_value::load_binary()", type_name ()); |
1106 | |
1107 | return false; |
1108 | } |
1109 | |
1110 | #endif |
1111 | |
1112 | int |
1113 | octave_base_value::write (octave_stream&, int, oct_data_conv::data_type, |
1114 | int, oct_mach_info::float_format) const |
1115 | { |
1116 | gripe_wrong_type_arg ("octave_base_value::write()", type_name ()); |
1117 | |
1118 | return false; |
1119 | } |
1120 | |
1121 | mxArray * |
1122 | octave_base_value::as_mxArray (void) const |
1123 | { |
1124 | return 0; |
1125 | } |
1126 | |
1127 | octave_value |
1128 | octave_base_value::diag (octave_idx_type) const |
1129 | { |
1130 | gripe_wrong_type_arg ("octave_base_value::diag ()", type_name ()); |
1131 | |
1132 | return octave_value (); |
1133 | } |
1134 | |
1135 | octave_value |
1136 | octave_base_value::diag (octave_idx_type, octave_idx_type) const |
1137 | { |
1138 | gripe_wrong_type_arg ("octave_base_value::diag ()", type_name ()); |
1139 | |
1140 | return octave_value (); |
1141 | } |
1142 | |
1143 | octave_value |
1144 | octave_base_value::sort (octave_idx_type, sortmode) const |
1145 | { |
1146 | gripe_wrong_type_arg ("octave_base_value::sort ()", type_name ()); |
1147 | |
1148 | return octave_value (); |
1149 | } |
1150 | |
1151 | octave_value |
1152 | octave_base_value::sort (Array<octave_idx_type> &, |
1153 | octave_idx_type, sortmode) const |
1154 | { |
1155 | gripe_wrong_type_arg ("octave_base_value::sort ()", type_name ()); |
1156 | |
1157 | return octave_value (); |
1158 | } |
1159 | |
1160 | sortmode |
1161 | octave_base_value::is_sorted (sortmode) const |
1162 | { |
1163 | gripe_wrong_type_arg ("octave_base_value::is_sorted ()", type_name ()); |
1164 | |
1165 | return UNSORTED; |
1166 | } |
1167 | |
1168 | Array<octave_idx_type> |
1169 | octave_base_value::sort_rows_idx (sortmode) const |
1170 | { |
1171 | gripe_wrong_type_arg ("octave_base_value::sort_rows_idx ()", type_name ()); |
1172 | |
1173 | return Array<octave_idx_type> (); |
1174 | } |
1175 | |
1176 | sortmode |
1177 | octave_base_value::is_sorted_rows (sortmode) const |
1178 | { |
1179 | gripe_wrong_type_arg ("octave_base_value::is_sorted_rows ()", type_name ()); |
1180 | |
1181 | return UNSORTED; |
1182 | } |
1183 | |
1184 | |
1185 | const char * |
1186 | octave_base_value::get_umap_name (unary_mapper_t umap) |
1187 | { |
1188 | static const char *names[num_unary_mappers] = |
1189 | { |
1190 | "abs", |
1191 | "acos", |
1192 | "acosh", |
1193 | "angle", |
1194 | "arg", |
1195 | "asin", |
1196 | "asinh", |
1197 | "atan", |
1198 | "atanh", |
1199 | "cbrt", |
1200 | "ceil", |
1201 | "conj", |
1202 | "cos", |
1203 | "cosh", |
1204 | "erf", |
1205 | "erfinv", |
1206 | "erfcinv", |
1207 | "erfc", |
1208 | "erfcx", |
1209 | "erfi", |
1210 | "dawson", |
1211 | "exp", |
1212 | "expm1", |
1213 | "finite", |
1214 | "fix", |
1215 | "floor", |
1216 | "gamma", |
1217 | "imag", |
1218 | "isinf", |
1219 | "isna", |
1220 | "isnan", |
1221 | "lgamma", |
1222 | "log", |
1223 | "log2", |
1224 | "log10", |
1225 | "log1p", |
1226 | "real", |
1227 | "round", |
1228 | "roundb", |
1229 | "signum", |
1230 | "sin", |
1231 | "sinh", |
1232 | "sqrt", |
1233 | "tan", |
1234 | "tanh", |
1235 | "isalnum", |
1236 | "isalpha", |
1237 | "isascii", |
1238 | "iscntrl", |
1239 | "isdigit", |
1240 | "isgraph", |
1241 | "islower", |
1242 | "isprint", |
1243 | "ispunct", |
1244 | "isspace", |
1245 | "isupper", |
1246 | "isxdigit", |
1247 | "signbit", |
1248 | "toascii", |
1249 | "tolower", |
1250 | "toupper" |
1251 | }; |
1252 | |
1253 | if (umap < 0 || umap >= num_unary_mappers) |
1254 | return "unknown"; |
1255 | else |
1256 | return names[umap]; |
1257 | } |
1258 | |
1259 | octave_value |
1260 | octave_base_value::map (unary_mapper_t umap) const |
1261 | { |
1262 | error ("%s: not defined for %s", get_umap_name (umap), type_name ().c_str ()); |
1263 | return octave_value (); |
1264 | } |
1265 | |
1266 | void |
1267 | octave_base_value::lock (void) |
1268 | { |
1269 | gripe_wrong_type_arg ("octave_base_value::lock ()", type_name ()); |
1270 | } |
1271 | |
1272 | void |
1273 | octave_base_value::unlock (void) |
1274 | { |
1275 | gripe_wrong_type_arg ("octave_base_value::unlock ()", type_name ()); |
1276 | } |
1277 | |
1278 | void |
1279 | octave_base_value::dump (std::ostream& os) const |
1280 | { |
1281 | dim_vector dv = this->dims (); |
1282 | |
1283 | os << "class: " << this->class_name () |
1284 | << " type: " << this->type_name () |
1285 | << " dims: " << dv.str (); |
1286 | } |
1287 | |
1288 | static void |
1289 | gripe_indexed_assignment (const std::string& tn1, const std::string& tn2) |
1290 | { |
1291 | error ("assignment of '%s' to indexed '%s' not implemented", |
1292 | tn2.c_str (), tn1.c_str ()); |
1293 | } |
1294 | |
1295 | static void |
1296 | gripe_assign_conversion_failed (const std::string& tn1, |
1297 | const std::string& tn2) |
1298 | { |
1299 | error ("type conversion for assignment of '%s' to indexed '%s' failed", |
1300 | tn2.c_str (), tn1.c_str ()); |
1301 | } |
1302 | |
1303 | static void |
1304 | gripe_no_conversion (const std::string& on, const std::string& tn1, |
1305 | const std::string& tn2) |
1306 | { |
1307 | error ("operator %s: no conversion for assignment of '%s' to indexed '%s'", |
1308 | on.c_str (), tn2.c_str (), tn1.c_str ()); |
1309 | } |
1310 | |
1311 | octave_value |
1312 | octave_base_value::numeric_assign (const std::string& type, |
1313 | const std::list<octave_value_list>& idx, |
1314 | const octave_value& rhs) |
1315 | { |
1316 | octave_value retval; |
1317 | |
1318 | if (idx.front ().empty ()) |
1319 | { |
1320 | error ("missing index in indexed assignment"); |
1321 | return retval; |
1322 | } |
1323 | |
1324 | int t_lhs = type_id (); |
1325 | int t_rhs = rhs.type_id (); |
1326 | |
1327 | octave_value_typeinfo::assign_op_fcn f |
1328 | = octave_value_typeinfo::lookup_assign_op (octave_value::op_asn_eq, |
1329 | t_lhs, t_rhs); |
1330 | |
1331 | bool done = false; |
1332 | |
1333 | if (f) |
1334 | { |
1335 | f (*this, idx.front (), rhs.get_rep ()); |
1336 | |
1337 | done = (! error_state); |
1338 | } |
1339 | |
1340 | if (done) |
1341 | { |
1342 | count++; |
1343 | retval = octave_value (this); |
1344 | } |
1345 | else |
1346 | { |
1347 | int t_result |
1348 | = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
1349 | |
1350 | if (t_result >= 0) |
1351 | { |
1352 | octave_base_value::type_conv_fcn cf |
1353 | = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
1354 | |
1355 | if (cf) |
1356 | { |
1357 | octave_base_value *tmp = cf (*this); |
1358 | |
1359 | if (tmp) |
1360 | { |
1361 | octave_value val (tmp); |
1362 | |
1363 | retval = val.subsasgn (type, idx, rhs); |
1364 | |
1365 | done = (! error_state); |
1366 | } |
1367 | else |
1368 | gripe_assign_conversion_failed (type_name (), |
1369 | rhs.type_name ()); |
1370 | } |
1371 | else |
1372 | gripe_indexed_assignment (type_name (), rhs.type_name ()); |
1373 | } |
1374 | |
1375 | if (! (done || error_state)) |
1376 | { |
1377 | octave_value tmp_rhs; |
1378 | |
1379 | octave_base_value::type_conv_info cf_rhs |
1380 | = rhs.numeric_conversion_function (); |
1381 | |
1382 | octave_base_value::type_conv_info cf_this |
1383 | = numeric_conversion_function (); |
1384 | |
1385 | // Try biased (one-sided) conversions first. |
1386 | if (cf_rhs.type_id () >= 0 |
1387 | && (octave_value_typeinfo::lookup_assign_op (octave_value::op_asn_eq, |
1388 | t_lhs, |
1389 | cf_rhs.type_id ()) |
1390 | || octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, |
1391 | cf_rhs.type_id ()) >= 0)) |
1392 | cf_this = 0; |
1393 | else if (cf_this.type_id () >= 0 |
1394 | && (octave_value_typeinfo::lookup_assign_op (octave_value::op_asn_eq, |
1395 | cf_this.type_id (), t_rhs) |
1396 | || octave_value_typeinfo::lookup_pref_assign_conv (cf_this.type_id (), |
1397 | t_rhs) >= 0)) |
1398 | cf_rhs = 0; |
1399 | |
1400 | if (cf_rhs) |
1401 | { |
1402 | octave_base_value *tmp = cf_rhs (rhs.get_rep ()); |
1403 | |
1404 | if (tmp) |
1405 | tmp_rhs = octave_value (tmp); |
1406 | else |
1407 | { |
1408 | gripe_assign_conversion_failed (type_name (), |
1409 | rhs.type_name ()); |
1410 | return octave_value (); |
1411 | } |
1412 | } |
1413 | else |
1414 | tmp_rhs = rhs; |
1415 | |
1416 | count++; |
1417 | octave_value tmp_lhs = octave_value (this); |
1418 | |
1419 | if (cf_this) |
1420 | { |
1421 | octave_base_value *tmp = cf_this (*this); |
1422 | |
1423 | if (tmp) |
1424 | tmp_lhs = octave_value (tmp); |
1425 | else |
1426 | { |
1427 | gripe_assign_conversion_failed (type_name (), |
1428 | rhs.type_name ()); |
1429 | return octave_value (); |
1430 | } |
1431 | } |
1432 | |
1433 | if (cf_this || cf_rhs) |
1434 | { |
1435 | retval = tmp_lhs.subsasgn (type, idx, tmp_rhs); |
1436 | |
1437 | done = (! error_state); |
Value stored to 'done' is never read | |
1438 | } |
1439 | else |
1440 | gripe_no_conversion (octave_value::assign_op_as_string |
1441 | (octave_value::op_asn_eq), |
1442 | type_name (), rhs.type_name ()); |
1443 | } |
1444 | } |
1445 | |
1446 | // The assignment may have converted to a type that is wider than |
1447 | // necessary. |
1448 | |
1449 | retval.maybe_mutate (); |
1450 | |
1451 | return retval; |
1452 | } |
1453 | |
1454 | // Current indentation. |
1455 | int octave_base_value::curr_print_indent_level = 0; |
1456 | |
1457 | // TRUE means we are at the beginning of a line. |
1458 | bool octave_base_value::beginning_of_line = true; |
1459 | |
1460 | // Each print() function should call this before printing anything. |
1461 | // |
1462 | // This doesn't need to be fast, but isn't there a better way? |
1463 | |
1464 | void |
1465 | octave_base_value::indent (std::ostream& os) const |
1466 | { |
1467 | assert (curr_print_indent_level >= 0)((curr_print_indent_level >= 0) ? static_cast<void> ( 0) : __assert_fail ("curr_print_indent_level >= 0", "octave-value/ov-base.cc" , 1467, __PRETTY_FUNCTION__)); |
1468 | |
1469 | if (beginning_of_line) |
1470 | { |
1471 | // FIXME: do we need this? |
1472 | // os << prefix; |
1473 | |
1474 | for (int i = 0; i < curr_print_indent_level; i++) |
1475 | os << " "; |
1476 | |
1477 | beginning_of_line = false; |
1478 | } |
1479 | } |
1480 | |
1481 | // All print() functions should use this to print new lines. |
1482 | |
1483 | void |
1484 | octave_base_value::newline (std::ostream& os) const |
1485 | { |
1486 | os << "\n"; |
1487 | |
1488 | beginning_of_line = true; |
1489 | } |
1490 | |
1491 | // For ressetting print state. |
1492 | |
1493 | void |
1494 | octave_base_value::reset (void) const |
1495 | { |
1496 | beginning_of_line = true; |
1497 | curr_print_indent_level = 0; |
1498 | } |
1499 | |
1500 | |
1501 | octave_value |
1502 | octave_base_value::fast_elem_extract (octave_idx_type) const |
1503 | { |
1504 | return octave_value (); |
1505 | } |
1506 | |
1507 | bool |
1508 | octave_base_value::fast_elem_insert (octave_idx_type, const octave_value&) |
1509 | { |
1510 | return false; |
1511 | } |
1512 | |
1513 | bool |
1514 | octave_base_value::fast_elem_insert_self (void *, builtin_type_t) const |
1515 | { |
1516 | return false; |
1517 | } |
1518 | |
1519 | CONVDECLX (matrix_conv)static octave_base_value * oct_conv_matrix_conv (const octave_base_value &) |
1520 | { |
1521 | return new octave_matrix (); |
1522 | } |
1523 | |
1524 | CONVDECLX (complex_matrix_conv)static octave_base_value * oct_conv_complex_matrix_conv (const octave_base_value&) |
1525 | { |
1526 | return new octave_complex_matrix (); |
1527 | } |
1528 | |
1529 | CONVDECLX (string_conv)static octave_base_value * oct_conv_string_conv (const octave_base_value &) |
1530 | { |
1531 | return new octave_char_matrix_str (); |
1532 | } |
1533 | |
1534 | CONVDECLX (cell_conv)static octave_base_value * oct_conv_cell_conv (const octave_base_value &) |
1535 | { |
1536 | return new octave_cell (); |
1537 | } |
1538 | |
1539 | void |
1540 | install_base_type_conversions (void) |
1541 | { |
1542 | INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_matrix)octave_value_typeinfo::register_pref_assign_conv (octave_base_value ::static_type_id (), octave_scalar::static_type_id (), octave_matrix ::static_type_id ());; |
1543 | INSTALL_ASSIGNCONV (octave_base_value, octave_matrix, octave_matrix)octave_value_typeinfo::register_pref_assign_conv (octave_base_value ::static_type_id (), octave_matrix::static_type_id (), octave_matrix ::static_type_id ());; |
1544 | INSTALL_ASSIGNCONV (octave_base_value, octave_complex, octave_complex_matrix)octave_value_typeinfo::register_pref_assign_conv (octave_base_value ::static_type_id (), octave_complex::static_type_id (), octave_complex_matrix ::static_type_id ());; |
1545 | INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix,octave_value_typeinfo::register_pref_assign_conv (octave_base_value ::static_type_id (), octave_complex_matrix::static_type_id () , octave_complex_matrix::static_type_id ()); |
1546 | octave_complex_matrix)octave_value_typeinfo::register_pref_assign_conv (octave_base_value ::static_type_id (), octave_complex_matrix::static_type_id () , octave_complex_matrix::static_type_id ());; |
1547 | INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix)octave_value_typeinfo::register_pref_assign_conv (octave_base_value ::static_type_id (), octave_range::static_type_id (), octave_matrix ::static_type_id ());; |
1548 | INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str,octave_value_typeinfo::register_pref_assign_conv (octave_base_value ::static_type_id (), octave_char_matrix_str::static_type_id ( ), octave_char_matrix_str::static_type_id ()); |
1549 | octave_char_matrix_str)octave_value_typeinfo::register_pref_assign_conv (octave_base_value ::static_type_id (), octave_char_matrix_str::static_type_id ( ), octave_char_matrix_str::static_type_id ());; |
1550 | INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell)octave_value_typeinfo::register_pref_assign_conv (octave_base_value ::static_type_id (), octave_cell::static_type_id (), octave_cell ::static_type_id ());; |
1551 | |
1552 | INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv)octave_value_typeinfo::register_widening_op (octave_base_value ::static_type_id (), octave_matrix::static_type_id (), oct_conv_matrix_conv );; |
1553 | INSTALL_WIDENOP (octave_base_value, octave_complex_matrix,octave_value_typeinfo::register_widening_op (octave_base_value ::static_type_id (), octave_complex_matrix::static_type_id () , oct_conv_complex_matrix_conv); |
1554 | complex_matrix_conv)octave_value_typeinfo::register_widening_op (octave_base_value ::static_type_id (), octave_complex_matrix::static_type_id () , oct_conv_complex_matrix_conv);; |
1555 | INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv)octave_value_typeinfo::register_widening_op (octave_base_value ::static_type_id (), octave_char_matrix_str::static_type_id ( ), oct_conv_string_conv);; |
1556 | INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv)octave_value_typeinfo::register_widening_op (octave_base_value ::static_type_id (), octave_cell::static_type_id (), oct_conv_cell_conv );; |
1557 | } |
1558 | |
1559 | DEFUN (sparse_auto_mutate, args, nargout,octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1560 | "-*- texinfo -*-\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1561 | @deftypefn {Built-in Function} {@var{val} =} sparse_auto_mutate ()\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1562 | @deftypefnx {Built-in Function} {@var{old_val} =} sparse_auto_mutate (@var{new_val})\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1563 | @deftypefnx {Built-in Function} {} sparse_auto_mutate (@var{new_val}, \"local\")\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1564 | Query or set the internal variable that controls whether Octave will\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1565 | automatically mutate sparse matrices to full matrices to save memory.\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1566 | For example:\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1567 | \n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1568 | @example\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1569 | @group\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1570 | s = speye (3);\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1571 | sparse_auto_mutate (false);\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1572 | s(:, 1) = 1;\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1573 | typeinfo (s)\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1574 | @result{} sparse matrix\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1575 | sparse_auto_mutate (true);\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1576 | s(1, :) = 1;\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1577 | typeinfo (s)\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1578 | @result{} matrix\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1579 | @end group\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1580 | @end example\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1581 | \n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1582 | When called from inside a function with the @qcode{\"local\"} option, the\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1583 | variable is changed locally for the function and any subroutines it calls. \n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1584 | The original variable value is restored when exiting the function.\n\octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1585 | @end deftypefn")octave_value_list Fsparse_auto_mutate (const octave_value_list & args, int nargout) |
1586 | { |
1587 | return SET_INTERNAL_VARIABLE (sparse_auto_mutate)set_internal_variable (Vsparse_auto_mutate, args, nargout, "sparse_auto_mutate" ); |
1588 | } |
1589 | |
1590 | /* |
1591 | %!test |
1592 | %! s = speye (3); |
1593 | %! sparse_auto_mutate (false); |
1594 | %! s(:, 1) = 1; |
1595 | %! assert (typeinfo (s), "sparse matrix"); |
1596 | %! sparse_auto_mutate (true); |
1597 | %! s(1, :) = 1; |
1598 | %! assert (typeinfo (s), "matrix"); |
1599 | %! sparse_auto_mutate (false); |
1600 | */ |