comparison libinterp/octave-value/ov.cc @ 19589:b39cbe9f3bb0

allow ranges to be disabled * ov.cc, ov.h: Allow creation of range object to be disabled. Also allow range objects to be forced, even when generally disabled. * pt-exp.h (tree_expression::for_cmd_expr): New member variable. (tree_expression::mark_as_for_cmd_expr, tree_expression::is_for_cmd_expr): New functions. * oct-parse.in.yy: Mark for command expressions. * pt-colon.cc (tree_colon_expression::make_range): Force creation of range if expression is a for command expression. * basics.txi, numbers.txi: Document changes.
author John W. Eaton <jwe@octave.org>
date Mon, 08 Dec 2014 12:59:47 -0500
parents 385499581a5e
children 9e5b64b3c1fe
comparison
equal deleted inserted replaced
19588:9464cfeede2b 19589:b39cbe9f3bb0
101 101
102 // If TRUE, don't create special permutation matrix objects. 102 // If TRUE, don't create special permutation matrix objects.
103 103
104 static bool Vdisable_permutation_matrix = false; 104 static bool Vdisable_permutation_matrix = false;
105 105
106 // If TRUE, don't create special range objects.
107
108 static bool Vdisable_range = false;
109
106 // FIXME 110 // FIXME
107 111
108 // Octave's value type. 112 // Octave's value type.
109 113
110 std::string 114 std::string
1201 : rep (new octave_range (base, limit, inc)) 1205 : rep (new octave_range (base, limit, inc))
1202 { 1206 {
1203 maybe_mutate (); 1207 maybe_mutate ();
1204 } 1208 }
1205 1209
1206 octave_value::octave_value (const Range& r) 1210 octave_value::octave_value (const Range& r, bool force_range)
1207 : rep (new octave_range (r)) 1211 : rep (force_range || ! Vdisable_range
1212 ? dynamic_cast<octave_base_value *> (new octave_range (r))
1213 : dynamic_cast<octave_base_value *> (new octave_matrix (r.matrix_value ())))
1208 { 1214 {
1209 maybe_mutate (); 1215 maybe_mutate ();
1210 } 1216 }
1211 1217
1212 octave_value::octave_value (const octave_map& m) 1218 octave_value::octave_value (const octave_map& m)
3242 %!assert (typeinfo (x), "matrix"); 3248 %!assert (typeinfo (x), "matrix");
3243 %!assert (typeinfo (xi), "complex matrix"); 3249 %!assert (typeinfo (xi), "complex matrix");
3244 %!assert (typeinfo (fx), "float matrix"); 3250 %!assert (typeinfo (fx), "float matrix");
3245 %!assert (typeinfo (fxi), "float complex matrix"); 3251 %!assert (typeinfo (fxi), "float complex matrix");
3246 */ 3252 */
3253
3254 DEFUN (disable_range, args, nargout,
3255 "-*- texinfo -*-\n\
3256 @deftypefn {Built-in Function} {@var{val} =} disable_range ()\n\
3257 @deftypefnx {Built-in Function} {@var{old_val} =} disable_range (@var{new_val})\n\
3258 @deftypefnx {Built-in Function} {} disable_range (@var{new_val}, \"local\")\n\
3259 Query or set the internal variable that controls whether permutation\n\
3260 matrices are stored in a special space-efficient format. The default\n\
3261 value is true. If this option is disabled Octave will store permutation\n\
3262 matrices as full matrices.\n\
3263 \n\
3264 When called from inside a function with the @qcode{\"local\"} option, the\n\
3265 variable is changed locally for the function and any subroutines it calls.\n\
3266 The original variable value is restored when exiting the function.\n\
3267 @end deftypefn")
3268 {
3269 return SET_INTERNAL_VARIABLE (disable_range);
3270 }
3271
3272 /*
3273 %!function r = __test_dr__ (dr)
3274 %! disable_range (dr, "local");
3275 %! ## Constant folding will produce range for 1:13.
3276 %! base = 1;
3277 %! limit = 13;
3278 %! r = base:limit;
3279 %!endfunction
3280
3281 %!assert (typeinfo (__test_dr__ (false)), "range");
3282 %!assert (typeinfo (__test_dr__ (true)), "matrix");
3283 */
3284