Mercurial > hg > octave-terminal
changeset 10613:e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 07 May 2010 15:58:51 -0400 |
parents | 09e244649f50 |
children | d1194069e58c |
files | doc/ChangeLog doc/interpreter/basics.txi src/ChangeLog src/octave.cc src/ov-range.cc src/ov-range.h src/utils.cc |
diffstat | 7 files changed, 75 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2010-05-07 John W. Eaton <jwe@octave.org> + + * basics.txi: Update list of internal variables for --traditional. + 2010-05-02 Rik <octave@nomad.inbox5.com> * interpreter/contrib.txi, interpreter/install.txi,
--- a/doc/interpreter/basics.txi +++ b/doc/interpreter/basics.txi @@ -209,17 +209,17 @@ @example @group -PS1 = ">> " -PS2 = "" -beep_on_error = true -confirm_recursive_rmdir = false -crash_dumps_octave_core = false -default_save_options = "-mat-binary" -fixed_point_format = true -history_timestamp_format_string - = "%%-- %D %I:%M %p --%%" -page_screen_output = false -print_empty_dimensions = false +PS1 = ">> " +PS2 = "" +allow_noninteger_range_as_index = true +beep_on_error = true +confirm_recursive_rmdir = false +crash_dumps_octave_core = false +default_save_options = "-mat-binary" +fixed_point_format = true +history_timestamp_format_string = "%%-- %D %I:%M %p --%%" +page_screen_output = false +print_empty_dimensions = false @end group @end example @@ -227,6 +227,7 @@ and disable the following warnings @example @group +Octave:abbreviated-property-match Octave:fopen-file-in-path Octave:function-name-clash Octave:load-file-in-path
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -2,6 +2,22 @@ * ov-base.h (Vsparse_auto_mutate): Add OCTINTERP_API tag. +2010-05-07 John W. Eaton <jwe@octave.org> + + * octave.cc (maximum_braindamage): Set value of internal + variable Vallow_noninteger_range_as_index to true instead of + setting Octave:allow-noninteger-ranges-as-indices warning state. + * ov-range.cc (Fallow_noninteger_range_as_index): New function. + (Vallow_noninteger_range_as_index): New variable. + (octave_range::index_vector): Only allow non-integer range as + index if Vallow_noninteger_range_as_index is true. + (octave_range::bool_array_value): Move definition here from ov-range.h. + * ov-range.h (Vallow_noninteger_range_as_index): Provide decl. + * utils.cc (reset_warning_state): Delete. + (Fisindex): Temporarily set Vallow_noninteger_range_as_index + instead of changing warning state for + Octave:allow-noninteger-ranges-as-indices to "error". + 2010-05-06 John W. Eaton <jwe@octave.org> * xgl2ps.c: Don't compile gl2ps.c unless we have OpenGL.
--- a/src/octave.cc +++ b/src/octave.cc @@ -59,12 +59,13 @@ #include "oct-map.h" #include "oct-obj.h" #include "ops.h" +#include "ov.h" +#include "ov-range.h" #include "toplev.h" #include "parse.h" #include "procstream.h" #include "sighandlers.h" #include "sysdep.h" -#include "ov.h" #include "unwind-prot.h" #include "utils.h" #include "variables.h" @@ -563,6 +564,7 @@ bind_internal_variable ("PS1", ">> "); bind_internal_variable ("PS2", ""); + bind_internal_variable ("allow_noninteger_range_as_index", true); bind_internal_variable ("beep_on_error", true); bind_internal_variable ("confirm_recursive_rmdir", false); bind_internal_variable ("crash_dumps_octave_core", false); @@ -573,8 +575,6 @@ bind_internal_variable ("page_screen_output", false); bind_internal_variable ("print_empty_dimensions", false); - set_warning_state ("Octave:allow-noninteger-ranges-as-indices", "on"); - disable_warning ("Octave:abbreviated-property-match"); disable_warning ("Octave:fopen-file-in-path"); disable_warning ("Octave:function-name-clash");
--- a/src/ov-range.cc +++ b/src/ov-range.cc @@ -45,6 +45,9 @@ #include "ls-hdf5.h" #include "ls-utils.h" +// If TRUE, allow ranges with non-integer elements as array indices. +bool Vallow_noninteger_range_as_index = false; + DEFINE_OCTAVE_ALLOCATOR (octave_range); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_range, "range", "double"); @@ -151,11 +154,12 @@ return *idx_cache; else { - if (range.all_elements_are_ints ()) + if (range.all_elements_are_ints () + || ! Vallow_noninteger_range_as_index) return set_idx_cache (idx_vector (range)); else { - warning_with_id ("Octave:allow-noninteger-ranges-as-indices", + warning_with_id ("Octave:noninteger-range-as-index", "non-integer range used as index"); return octave_value (matrix_value ()).round ().index_vector (); @@ -307,12 +311,25 @@ return retval; } +boolNDArray +octave_range::bool_array_value (bool warn) const +{ + Matrix m = range.matrix_value (); + + if (m.any_element_is_nan ()) + error ("invalid conversion from NaN to logical"); + else if (warn && m.any_element_not_one_or_zero ()) + gripe_logical_conversion (); + + return boolNDArray (m); +} + octave_value octave_range::resize (const dim_vector& dv, bool fill) const { NDArray retval = array_value (); if (fill) - retval.resize (dv, NDArray::resize_fill_value()); + retval.resize (dv, NDArray::resize_fill_value ()); else retval.resize (dv); return retval; @@ -589,3 +606,16 @@ return retval; } + +DEFUN (allow_noninteger_range_as_index, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} allow_noninteger_range_as_index ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} allow_noninteger_range_as_index (@var{new_val})\n\ +Query or set the internal variable that controls whether non-integer\n\ +ranges are allowed as indices. This might be useful for Matlab\n\ +compatibility; however, it is still not entirely compatible because\n\ +Matlab treats the range expression differently in different contexts.\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (allow_noninteger_range_as_index); +}
--- a/src/ov-range.h +++ b/src/ov-range.h @@ -231,17 +231,7 @@ FloatComplex float_complex_value (bool = false) const; - boolNDArray bool_array_value (bool warn = false) const - { - Matrix m = range.matrix_value (); - - if (m.any_element_is_nan ()) - error ("invalid conversion from NaN to logical"); - else if (warn && m.any_element_not_one_or_zero ()) - gripe_logical_conversion (); - - return boolNDArray (m); - } + boolNDArray bool_array_value (bool warn = false) const; ComplexMatrix complex_matrix_value (bool = false) const { return ComplexMatrix (range.matrix_value ()); } @@ -322,4 +312,7 @@ DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; +// If TRUE, allow ranges with non-integer elements as array indices. +extern bool Vallow_noninteger_range_as_index; + #endif
--- a/src/utils.cc +++ b/src/utils.cc @@ -59,6 +59,7 @@ #include "oct-errno.h" #include "oct-hist.h" #include "oct-obj.h" +#include "ov-range.h" #include "pager.h" #include "parse.h" #include "sysdep.h" @@ -1304,17 +1305,6 @@ } } -// FIXME -- is there some way to fix the declarations in unwind-prot.h -// so that this function's argument can be declared as -// "const octave_value_list&"? - -static void -reset_warning_state (octave_value_list args) -{ - if (! args.empty ()) - set_warning_state (args); -} - DEFUN (isindex, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} isindex (@var{ind}, @var{n})\n\ @@ -1338,11 +1328,8 @@ { unwind_protect frame; - octave_value_list current_warning_state - = set_warning_state ("Octave:allow-noninteger-ranges-as-indices", - "error"); - - frame.add_fcn (reset_warning_state, current_warning_state); + frame.protect_var (Vallow_noninteger_range_as_index); + Vallow_noninteger_range_as_index = false; frame.protect_var (error_state);