Mercurial > octave-antonio
diff libinterp/octave-value/ov.cc @ 19394: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 |
line wrap: on
line diff
--- a/libinterp/octave-value/ov.cc Mon Dec 08 10:18:35 2014 -0500 +++ b/libinterp/octave-value/ov.cc Mon Dec 08 12:59:47 2014 -0500 @@ -103,6 +103,10 @@ static bool Vdisable_permutation_matrix = false; +// If TRUE, don't create special range objects. + +static bool Vdisable_range = false; + // FIXME // Octave's value type. @@ -1203,8 +1207,10 @@ maybe_mutate (); } -octave_value::octave_value (const Range& r) - : rep (new octave_range (r)) +octave_value::octave_value (const Range& r, bool force_range) + : rep (force_range || ! Vdisable_range + ? dynamic_cast<octave_base_value *> (new octave_range (r)) + : dynamic_cast<octave_base_value *> (new octave_matrix (r.matrix_value ()))) { maybe_mutate (); } @@ -3244,3 +3250,35 @@ %!assert (typeinfo (fx), "float matrix"); %!assert (typeinfo (fxi), "float complex matrix"); */ + +DEFUN (disable_range, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} disable_range ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} disable_range (@var{new_val})\n\ +@deftypefnx {Built-in Function} {} disable_range (@var{new_val}, \"local\")\n\ +Query or set the internal variable that controls whether permutation\n\ +matrices are stored in a special space-efficient format. The default\n\ +value is true. If this option is disabled Octave will store permutation\n\ +matrices as full matrices.\n\ +\n\ +When called from inside a function with the @qcode{\"local\"} option, the\n\ +variable is changed locally for the function and any subroutines it calls.\n\ +The original variable value is restored when exiting the function.\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (disable_range); +} + +/* +%!function r = __test_dr__ (dr) +%! disable_range (dr, "local"); +%! ## Constant folding will produce range for 1:13. +%! base = 1; +%! limit = 13; +%! r = base:limit; +%!endfunction + +%!assert (typeinfo (__test_dr__ (false)), "range"); +%!assert (typeinfo (__test_dr__ (true)), "matrix"); +*/ +