Mercurial > hg > octave-nkf
changeset 4455:abbf63293766
[project @ 2003-07-11 01:01:16 by jwe]
author | jwe |
---|---|
date | Fri, 11 Jul 2003 01:01:17 +0000 |
parents | c474333062d9 |
children | b0aff7648c2d |
files | ChangeLog doc/faq/Octave-FAQ.texi doc/interpreter/basics.txi doc/interpreter/emacs.txi doc/interpreter/eos.txi doc/interpreter/expr.txi doc/interpreter/stmt.txi doc/interpreter/var.txi emacs/octave-mod.el liboctave/Array-flags.cc liboctave/Array-flags.h liboctave/Array2-idx.h liboctave/ChangeLog scripts/ChangeLog scripts/general/reshape.m scripts/miscellaneous/dump_prefs.m scripts/strings/strjust.m src/ChangeLog src/data.cc src/octave.cc src/ov-bool-mat.cc src/ov-ch-mat.cc src/ov-cx-mat.cc src/ov-range.cc src/ov-re-mat.cc src/ov-re-nd-array.cc src/ov.cc src/ov.h |
diffstat | 28 files changed, 297 insertions(+), 254 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -3,9 +3,11 @@ * emacs/octave-mod.el (octave-variables): Include DEFAULT_EXEC_PATH, DEFAULT_LOAD_PATH, crash_dumps_octave_core, sighup_dumps_octave_core, sigterm_dumps_octave_core, - warn_imag_to_real, warn_num_to_str, and warn_str_to_num in the list. - Delete ok_to_lose_imaginary_part, implicit_num_to_str_ok, and - implicit_str_to_num_ok from the list. + warn_imag_to_real, warn_num_to_str, warn_str_to_num, and + warn_fortran_indexing in the list. + Delete ok_to_lose_imaginary_part, implicit_num_to_str_ok, + implicit_str_to_num_ok, prefer_column_vectors, + prefer_zero_one_indexing, and do_fortran_indexing from the list. 2003-07-08 John W. Eaton <jwe@bevo.che.wisc.edu>
--- a/doc/faq/Octave-FAQ.texi +++ b/doc/faq/Octave-FAQ.texi @@ -716,22 +716,21 @@ @example @group - PS1 = ">> " - PS2 = "" - beep_on_error = 1.0 - default_eval_print_flag = 0.0 - default_save_format = "mat-binary" - define_all_return_values = 1.0 - do_fortran_indexing = 1.0 - empty_list_elements_ok = 1.0 - fixed_point_format = 1.0 - page_screen_output = 0.0 - prefer_column_vectors = 0.0 - prefer_zero_one_indexing = 1.0 - print_empty_dimensions = 0.0 - treat_neg_dim_as_zero = 1.0 - warn_function_name_clash = 0.0 - whitespace_in_literal_matrix = "traditional" + PS1 = ">> " + PS2 = "" + beep_on_error = true + crash_dumps_octave_core = false + default_eval_print_flag = false + default_global_variable_value = [] + default_save_format = "mat-binary" + define_all_return_values = true + fixed_point_format = true + initialize_global_variables = true + page_screen_output = false + print_empty_dimensions = false + treat_neg_dim_as_zero = true + warn_function_name_clash = false + whitespace_in_literal_matrix = "traditional" @end group @end example
--- a/doc/interpreter/basics.txi +++ b/doc/interpreter/basics.txi @@ -155,20 +155,23 @@ values for compatibility with @sc{Matlab}. @example -PS1 = ">> " -PS2 = "" -beep_on_error = 1 -default_save_format = "mat-binary" -define_all_return_values = 1 -do_fortran_indexing = 1 -crash_dumps_octave_core = 0 -empty_list_elements_ok = 1 -page_screen_output = 0 -prefer_column_vectors = 0 -print_empty_dimensions = 0 -treat_neg_dim_as_zero = 1 -warn_function_name_clash = 0 -whitespace_in_literal_matrix = "traditional" +@group + PS1 = ">> " + PS2 = "" + beep_on_error = true + crash_dumps_octave_core = false + default_eval_print_flag = false + default_global_variable_value = [] + default_save_format = "mat-binary" + define_all_return_values = true + fixed_point_format = true + initialize_global_variables = true + page_screen_output = false + print_empty_dimensions = false + treat_neg_dim_as_zero = true + warn_function_name_clash = false + whitespace_in_literal_matrix = "traditional" +@end group @end example @item --verbose
--- a/doc/interpreter/emacs.txi +++ b/doc/interpreter/emacs.txi @@ -327,7 +327,7 @@ the builtin operators (@samp{&&}, @samp{<>}, @dots{}) using @code{font-lock-reference-face} @item -the builtin variables (such as @samp{prefer_column_vectors}, @samp{NaN} +the builtin variables (such as @samp{warn_fortran_indexing}, @samp{NaN} or @samp{LOADPATH}) in @code{font-lock-variable-name-face} @item and the function names in function declarations in
--- a/doc/interpreter/eos.txi +++ b/doc/interpreter/eos.txi @@ -327,7 +327,7 @@ the builtin operators (@samp{&&}, @samp{<>}, @dots{}) using @code{font-lock-reference-face} @item -the builtin variables (such as @samp{prefer_column_vectors}, @samp{NaN} +the builtin variables (such as @samp{warn_fortran_indexing}, @samp{NaN} or @samp{LOADPATH}) in @code{font-lock-variable-name-face} @item and the function names in function declarations in
--- a/doc/interpreter/expr.txi +++ b/doc/interpreter/expr.txi @@ -40,12 +40,12 @@ Indices may be scalars, vectors, ranges, or the special operator @samp{:}, which may be used to select entire rows or columns. -Vectors are indexed using a single expression. Matrices require two -indices unless the value of the built-in variable -@code{do_fortran_indexing} is nonzero, in which case matrices may -also be indexed by a single expression. +Vectors are indexed using a single expression. Matrices may be +indexed using one or two indices (a warning is issued if a single +index is used unless the value of the built-in variable +@code{warn_fortran_indexing} is zero). -@DOCSTRING(do_fortran_indexing) +@DOCSTRING(warn_fortran_indexing) Given the matrix @@ -167,8 +167,6 @@ size whose elements are all one, and then to scale it to produce the desired result. @xref{Special Utility Matrices}. -@DOCSTRING(prefer_column_vectors) - @DOCSTRING(resize_on_range_error) Note that it is quite inefficient to create a vector using a loop like
--- a/doc/interpreter/stmt.txi +++ b/doc/interpreter/stmt.txi @@ -667,22 +667,22 @@ This is useful to protect temporary changes to global variables from possible errors. For example, the following code will always restore -the original value of the built-in variable @code{do_fortran_indexing} +the original value of the built-in variable @code{warn_fortran_indexing} even if an error occurs while performing the indexing operation. @example @group -save_do_fortran_indexing = do_fortran_indexing; +save_warn_fortran_indexing = warn_fortran_indexing; unwind_protect - do_fortran_indexing = 1; + warn_fortran_indexing = 1; elt = a (idx) unwind_protect_cleanup - do_fortran_indexing = save_do_fortran_indexing; + warn_fortran_indexing = save_warn_fortran_indexing; end_unwind_protect @end group @end example -Without @code{unwind_protect}, the value of @var{do_fortran_indexing} +Without @code{unwind_protect}, the value of @var{warn_fortran_indexing} would not be restored if an error occurs while performing the indexing operation because evaluation would stop at the point of the error and the statement to restore the value would not be executed.
--- a/doc/interpreter/var.txi +++ b/doc/interpreter/var.txi @@ -256,11 +256,6 @@ Default value: @code{"ascii"}. -@item do_fortran_indexing -@xref{Index Expressions}. - -Default value: 0. - @item crash_dumps_octave_core @xref{Simple File I/O}. @@ -321,11 +316,6 @@ Default value: 1. -@item prefer_column_vectors -@xref{Index Expressions}. - -Default value: 1. - @item print_answer_id_name @xref{Terminal Output}. @@ -406,6 +396,11 @@ Default value: 1. +@item warn_fortran_indexing +@xref{Index Expressions}. + +Default value: 0. + @item warn_function_name_clash @xref{Function Files}.
--- a/emacs/octave-mod.el +++ b/emacs/octave-mod.el @@ -142,14 +142,13 @@ "automatic_replot" "beep_on_error" "completion_append_char" "crash_dumps_octave_core" "default_return_value" "default_save_format" - "define_all_return_values" "do_fortran_indexing" "e" + "define_all_return_values" "e" "echo_executing_commands" "empty_list_elements_ok" "eps" "error_text" "gnuplot_binary" "history_file" "history_size" "ignore_function_time_stamp" "inf" "nan" "nargin" "output_max_field_width" "output_precision" "page_output_immediately" "page_screen_output" "pi" - "prefer_column_vectors" "prefer_zero_one_indexing" "print_answer_id_name" "print_empty_dimensions" "program_invocation_name" "program_name" "propagate_empty_matrices" "realmax" "realmin" "resize_on_range_error" @@ -159,7 +158,7 @@ "string_fill_char" "struct_levels_to_print" "suppress_verbose_help_message" "treat_neg_dim_as_zero" "warn_assign_as_truth_value" "warn_comma_in_global_decl" - "warn_divide_by_zero" "warn_function_name_clash" + "warn_divide_by_zero" "warn_fortran_indexing" "warn_function_name_clash" "warn_imag_to_real" "warn_missing_semicolon" "warn_num_to_str" "warn_str_to_num" "whitespace_in_literal_matrix") "Builtin variables in Octave.")
--- a/liboctave/Array-flags.cc +++ b/liboctave/Array-flags.cc @@ -30,8 +30,7 @@ #if defined (HEAVYWEIGHT_INDEXING) -int liboctave_dfi_flag = 0; -int liboctave_pcv_flag = 0; +int liboctave_wfi_flag = 0; int liboctave_rre_flag = 0; #endif
--- a/liboctave/Array-flags.h +++ b/liboctave/Array-flags.h @@ -21,8 +21,7 @@ */ #if defined (OCTAVE_SOURCE) -extern int liboctave_dfi_flag; -extern int liboctave_pcv_flag; +extern int liboctave_wfi_flag; extern int liboctave_rre_flag; #endif
--- a/liboctave/Array2-idx.h +++ b/liboctave/Array2-idx.h @@ -119,11 +119,14 @@ retval = Array2<T> (tmp, idx_orig_rows, idx_orig_columns); } } - else if (liboctave_dfi_flag - || (idx_arg.one_zero_only () - && idx_orig_rows == nr - && idx_orig_columns == nc)) + else { + if (liboctave_wfi_flag + && ! (idx_arg.one_zero_only () + && idx_orig_rows == nr + && idx_orig_columns == nc)) + (*current_liboctave_warning_handler) ("single index used for matrix"); + // This code is only for indexing matrices. The vector // cases are handled above. @@ -161,9 +164,6 @@ } // idx_vector::freeze() printed an error message for us. } - else - (*current_liboctave_error_handler) - ("single index only valid for row or column vector"); return retval; } @@ -626,75 +626,40 @@ if (n != 0 && (lhs_nr != 0 || lhs_nc != 0)) lhs.maybe_delete_elements (idx_i); } - else if (! liboctave_dfi_flag && lhs_is_empty - && idx_i.is_colon () - && ! (rhs_nr == 1 || rhs_nc == 1)) - { - (*current_liboctave_error_handler) - ("A(:) = X: X must be a vector"); - } else { + if (liboctave_wfi_flag) + { + if (lhs_is_empty + && idx_i.is_colon () + && ! (rhs_nr == 1 || rhs_nc == 1)) + { + (*current_liboctave_warning_handler) + ("A(:) = X: X is not a vector or scalar"); + } + else + { + int idx_nr = idx_i.orig_rows (); + int idx_nc = idx_i.orig_columns (); + + if (! (rhs_nr == idx_nr && rhs_nc == idx_nc)) + (*current_liboctave_warning_handler) + ("A(I) = X: X does not have same shape as I"); + } + } + if (assign ((Array<LT>&) lhs, (Array<RT>&) rhs)) { int len = lhs.length (); if (len > 0) { - int idx_nr = idx_i.orig_rows (); - int idx_nc = idx_i.orig_columns (); - - // lhs_is_empty now means that lhs was - // *originally* empty, and lhs_len is the - // *original* length of the lhs. + // The following behavior is much simplified + // over previous versions of Octave. It + // seems to be compatible with Matlab. - if (liboctave_dfi_flag - || (idx_nr == 1 && idx_nc == 1) - || (rhs_nr == 1 && rhs_nc == 1 && lhs_len == 1)) - { - if (liboctave_pcv_flag) - { - lhs.d1 = lhs.length (); - lhs.d2 = 1; - } - else - { - lhs.d1 = 1; - lhs.d2 = lhs.length (); - } - } - else if (lhs_is_empty && idx_i.is_colon ()) - { - lhs.d1 = rhs.d1; - lhs.d2 = rhs.d2; - } - else if (lhs_is_empty && idx_i.one_zero_only ()) - { - lhs.d1 = idx_nr; - lhs.d2 = idx_nc; - } - else if (rhs_nr == 1 - && (idx_nr == 1 || lhs_len == 1)) - { - lhs.d1 = 1; - lhs.d2 = lhs.length (); - } - else if (rhs_nc == 1 - && (idx_nc == 1 || lhs_len == 1)) - { - lhs.d1 = lhs.length (); - lhs.d2 = 1; - } - else if (idx_nr == 0 && idx_nc == 0) - { - if (! ((rhs.d1 == 1 && rhs.d2 == 1) - || (rhs.d1 == 0 && rhs.d2 == 0))) - (*current_liboctave_error_handler) - ("A([]) = X: X must be an empty matrix or scalar"); - } - else - (*current_liboctave_error_handler) - ("A(I) = X: X must be a scalar or a matrix with the same size as I"); + lhs.d1 = 1; + lhs.d2 = lhs.length (); } else { @@ -744,12 +709,16 @@ } // idx_vector::freeze() printed an error message for us. } - else if (liboctave_dfi_flag - || idx_i.is_colon () - || (idx_i.one_zero_only () - && idx_i.orig_rows () == lhs_nr - && idx_i.orig_columns () == lhs_nc)) + else { + if (liboctave_wfi_flag + && ! (idx_i.is_colon () + || (idx_i.one_zero_only () + && idx_i.orig_rows () == lhs_nr + && idx_i.orig_columns () == lhs_nc))) + (*current_liboctave_warning_handler) + ("single index used for matrix"); + int len = idx_i.freeze (lhs_nr * lhs_nc, "matrix"); if (idx_i) @@ -797,13 +766,6 @@ } // idx_vector::freeze() printed an error message for us. } - else - { - (*current_liboctave_error_handler) - ("single index only valid for row or column vector"); - - retval = 0; - } } else {
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,15 @@ +2003-07-09 John W. Eaton <jwe@bevo.che.wisc.edu> + + * Array-flags.cc, Array-flags.h (liboctave_pcv_flag): Delete. + + * Array2-idx.h (Array2<T>::index): Use liboctave_wfi_flag, not + liboctave_dfi_flag. + (assign): Likewise. For indexed assignments like X(I) = RHS with + X undefined or empty, always create a row vector. + + * Array-flags.cc (liboctave_wfi_flag): Rename from liboctave_dfi_flag. + * Array-flags.h (liboctave_wfi_flag): Ditto. + 2003-06-24 John W. Eaton <jwe@bevo.che.wisc.edu> * Array2-idx.h (Array2<T>::index (idx_vector&, int, const T&)):
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,15 +1,22 @@ 2003-07-09 John W. Eaton <jwe@bevo.che.wisc.edu> + * general/reshape.m: Omit do_fortran_indexing from doc string (it + was not used in the code in any case). + + * strings/strjust.m: Temporarily set warn_fortran_indexing, not + do_fortran_indexing. + * statistics/base/moment.m: Temporarily set warn_str_to_num, not implict_str_to_num_ok. Use unwind_protect block to do it. * miscellaneous/dump_prefs.m: Include DEFAULT_EXEC_PATH, DEFAULT_LOAD_PATH, crash_dumps_octave_core, sighup_dumps_octave_core, sigterm_dumps_octave_core, - warn_imag_to_real, warn_num_to_str, and warn_str_to_num in the - list. - Delete ok_to_lose_imaginary_part, implicit_num_to_str_ok, and - implicit_str_to_num_ok from list. + warn_imag_to_real, warn_num_to_str, warn_str_to_num, and + warn_fortran_indexing in the list. + Delete ok_to_lose_imaginary_part, implicit_num_to_str_ok, + implicit_str_to_num_ok, do_fortran_indexing, and + prefer_column_vectors from list. 2003-07-02 John W. Eaton <jwe@bevo.che.wisc.edu>
--- a/scripts/general/reshape.m +++ b/scripts/general/reshape.m @@ -34,8 +34,7 @@ ## @end group ## @end example ## -## If the variable @code{do_fortran_indexing} is nonzero, the -## @code{reshape} function is equivalent to +## The @code{reshape} function is equivalent to ## ## @example ## @group @@ -49,7 +48,7 @@ ## colon operator. Note that the total number of elements in the original ## matrix must match the total number of elements in the new matrix. ## @end deftypefn -## @seealso{`:' and do_fortran_indexing} +## @seealso{`:'} ## Author: jwe
--- a/scripts/miscellaneous/dump_prefs.m +++ b/scripts/miscellaneous/dump_prefs.m @@ -58,7 +58,6 @@ "default_return_value"; "default_save_format"; "define_all_return_values"; - "do_fortran_indexing"; "echo_executing_commands"; "empty_list_elements_ok"; "fixed_point_format"; @@ -80,7 +79,6 @@ "output_precision"; "page_output_immediately"; "page_screen_output"; - "prefer_column_vectors"; "print_answer_id_name"; "print_empty_dimensions"; "print_rhs_assign_val"; @@ -99,6 +97,7 @@ "treat_neg_dim_as_zero"; "warn_assign_as_truth_value"; "warn_divide_by_zero"; + "warn_fortran_indexing"; "warn_function_name_clash"; "warn_future_time_stamp"; "warn_imag_to_real";
--- a/scripts/strings/strjust.m +++ b/scripts/strings/strjust.m @@ -37,9 +37,9 @@ just = tolower (just); - dfi = do_fortran_indexing; + wfi = warn_fortran_indexing; unwind_protect - do_fortran_indexing = 1; + warn_fortran_indexing = 0; ## convert nulls to blanks idx = find (toascii (x) == 0); @@ -68,7 +68,7 @@ x = x (idx*nr + [1:nr]'*ones(1,nc)); unwind_protect_cleanup - do_fortran_indexing = dfi; + warn_fortran_indexing = wfi; end_unwind_protect endfunction
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,39 @@ 2003-07-09 John W. Eaton <jwe@bevo.che.wisc.edu> + * octave.cc (maximum_braindamage): Don't set prefer_column_vectors. + + * ov.cc (Vprefer_column_vectors): Delete. + (prefer_column_vectors): Delete. + (symbols_of_ov): Delete DEFVAR for prefer_column_vectors. + + * octave.cc (maximum_braindamage): Don't set do_fortran_indexing. + + * ov-re-mat.cc (octave_matrix::double_value, + octave_matrix::complex_value): Use Vwarn_fortran_indexing, not + Vdo_fortran_indexing. + * ov-range.cc (octave_range::double_value, + octave_range::complex_value): Likewise. + * ov-cx-mat.cc (octave_complex_matrix::double_value, + octave_complex_matrix::complex_value): Likewise. + * ov-ch-mat.cc (octave_char_matrix::double_value, + octave_char_matrix::complex_value): Likewise. + * ov-bool-mat.cc (octave_bool_matrix::double_value, + octave_bool_matrix::complex_value): Likewise. + + * ov.cc (Vwarn_fortran_indexing): New variable. + (warn_fortran_indexing): New function. + (symbols_of_ov): Add DEFVAR for warn_fortran_indexing. + (octave_value::vector_value, octave_value::int_vector_value, + (octave_value::complex_vector_value): Check + Vwarn_fortran_indexing, not Vdo_fortran_indexing. + + * ov.h (Vwarn_fortran_indexing): Provide decl. + + * ov.cc (Vdo_fortran_indexing): Delete unused variable. + (do_fortran_indexing): Delete unused function. + (symbols_of_ov): Delete DEFVAR for do_fortran_indexing. + * ov.h (Vdo_fortran_indexing): Delete decl. + * ov.cc (octave_value::convert_to_str): Call convert_to_str_internal. (octave_value::convert_to_str_internal): New virtual function. Rename all derived class convert_to_str functions to match.
--- a/src/data.cc +++ b/src/data.cc @@ -1098,8 +1098,7 @@ stored in decreasing order. If the number of points is not specified, a\n\ value of 100 is used.\n\ \n\ -The @code{linspace} function always returns a row vector, regardless of\n\ -the value of @code{prefer_column_vectors}.\n\ +The @code{linspace} function always returns a row vector.\n\ @end deftypefn") { octave_value retval;
--- a/src/octave.cc +++ b/src/octave.cc @@ -350,11 +350,9 @@ bind_builtin_variable ("default_global_variable_value", Matrix ()); bind_builtin_variable ("default_save_format", "mat-binary"); bind_builtin_variable ("define_all_return_values", true); - bind_builtin_variable ("do_fortran_indexing", true); bind_builtin_variable ("fixed_point_format", true); bind_builtin_variable ("initialize_global_variables", true); bind_builtin_variable ("page_screen_output", false); - bind_builtin_variable ("prefer_column_vectors", false); bind_builtin_variable ("print_empty_dimensions", false); bind_builtin_variable ("treat_neg_dim_as_zero", true); bind_builtin_variable ("warn_function_name_clash", false);
--- a/src/ov-bool-mat.cc +++ b/src/ov-bool-mat.cc @@ -90,9 +90,15 @@ { double retval = lo_ieee_nan_value (); - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = matrix (0, 0); + // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("bool matrix", "real scalar"); + + retval = matrix (0, 0); + } else gripe_invalid_conversion ("bool matrix", "real scalar"); @@ -106,9 +112,15 @@ Complex retval (tmp, tmp); - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = matrix (0, 0); + // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("bool matrix", "complex scalar"); + + retval = matrix (0, 0); + } else gripe_invalid_conversion ("bool matrix", "complex scalar");
--- a/src/ov-ch-mat.cc +++ b/src/ov-ch-mat.cc @@ -59,9 +59,15 @@ { double retval = lo_ieee_nan_value (); - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = matrix (0, 0); + // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("character matrix", "real scalar"); + + retval = matrix (0, 0); + } else gripe_invalid_conversion ("character matrix", "real scalar"); @@ -75,9 +81,15 @@ Complex retval (tmp, tmp); - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = matrix (0, 0); + // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("character matrix", "complex scalar"); + + retval = matrix (0, 0); + } else gripe_invalid_conversion ("character matrix", "complex scalar");
--- a/src/ov-cx-mat.cc +++ b/src/ov-cx-mat.cc @@ -135,9 +135,15 @@ if (! force_conversion && Vwarn_imag_to_real) gripe_implicit_conversion ("complex matrix", "real scalar"); - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = std::real (matrix (0, 0)); + // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("complex matrix", "real scalar"); + + retval = std::real (matrix (0, 0)); + } else gripe_invalid_conversion ("complex matrix", "real scalar"); @@ -164,9 +170,15 @@ Complex retval (tmp, tmp); - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = matrix (0, 0); + // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("complex matrix", "complex scalar"); + + retval = matrix (0, 0); + } else gripe_invalid_conversion ("complex matrix", "complex scalar");
--- a/src/ov-range.cc +++ b/src/ov-range.cc @@ -133,8 +133,14 @@ int nel = range.nelem (); - if (nel == 1 || (nel > 1 && Vdo_fortran_indexing)) - retval = range.base (); + if (nel > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("range", "real scalar"); + + retval = range.base (); + } else gripe_invalid_conversion ("range", "real scalar"); @@ -196,8 +202,14 @@ int nel = range.nelem (); - if (nel == 1 || (nel > 1 && Vdo_fortran_indexing)) - retval = range.base (); + if (nel > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("range", "complex scalar"); + + retval = range.base (); + } else gripe_invalid_conversion ("range", "complex scalar");
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -86,9 +86,14 @@ double retval = lo_ieee_nan_value (); // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = matrix (0, 0); + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("real matrix", "real scalar"); + + retval = matrix (0, 0); + } else gripe_invalid_conversion ("real matrix", "real scalar"); @@ -102,9 +107,15 @@ Complex retval (tmp, tmp); - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = matrix (0, 0); + // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("real matrix", "complex scalar"); + + retval = matrix (0, 0); + } else gripe_invalid_conversion ("real matrix", "complex scalar");
--- a/src/ov-re-nd-array.cc +++ b/src/ov-re-nd-array.cc @@ -116,9 +116,14 @@ double retval = lo_ieee_nan_value (); // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = matrix (0, 0); + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("real matrix", "real scalar"); + + retval = matrix (0, 0); + } else gripe_invalid_conversion ("real matrix", "real scalar"); @@ -132,9 +137,15 @@ Complex retval (tmp, tmp); - if ((rows () == 1 && columns () == 1) - || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) - retval = matrix (0, 0); + // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() + if (rows () > 0 && columns () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("real matrix", "complex scalar"); + + retval = matrix (0, 0); + } else gripe_invalid_conversion ("real matrix", "complex scalar");
--- a/src/ov.cc +++ b/src/ov.cc @@ -75,12 +75,12 @@ // semicolon has been appended to each statement). static bool Vsilent_functions; -// If TRUE, allow assignments like +// If TRUE, print a warning for assignments like // // octave> A(1) = 3; A(2) = 5 // // for A already defined and a matrix type. -bool Vdo_fortran_indexing; +bool Vwarn_fortran_indexing; // Should we warn about conversions from complex to real? int Vwarn_imag_to_real; @@ -96,14 +96,6 @@ // int Vwarn_str_to_num; -// If TRUE, create column vectors when doing assignments like: -// -// octave> A(1) = 3; A(2) = 5 -// -// (for A undefined). Only matters when resize_on_range_error is also -// TRUE. -static bool Vprefer_column_vectors; - // If TRUE, print the name along with the value. bool Vprint_answer_id_name; @@ -969,9 +961,12 @@ for (int i = 0; i < nr; i++) retval (i) = m (i, 0); } - else if (nr > 0 && nc > 0 - && (Vdo_fortran_indexing || force_vector_conversion)) + else if (nr > 0 && nc > 0) { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (! force_vector_conversion && Vwarn_fortran_indexing) + gripe_implicit_conversion (type_name (), "real vector"); + retval.resize (nr * nc); int k = 0; for (int j = 0; j < nc; j++) @@ -1041,9 +1036,12 @@ retval (i) = static_cast<int> (d); } } - else if (nr > 0 && nc > 0 - && (Vdo_fortran_indexing || force_vector_conversion)) + else if (nr > 0 && nc > 0) { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (! force_vector_conversion && Vwarn_fortran_indexing) + gripe_implicit_conversion (type_name (), "real vector"); + retval.resize (nr * nc); int k = 0; for (int j = 0; j < nc; j++) @@ -1105,9 +1103,12 @@ retval (i) = m (i, 0); } } - else if (nr > 0 && nc > 0 - && (Vdo_fortran_indexing || force_vector_conversion)) + else if (nr > 0 && nc > 0) { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (! force_vector_conversion && Vwarn_fortran_indexing) + gripe_implicit_conversion (type_name (), "complex vector"); + retval.resize (nr * nc); int k = 0; for (int j = 0; j < nc; j++) @@ -1753,11 +1754,11 @@ } static int -do_fortran_indexing (void) +warn_fortran_indexing (void) { - Vdo_fortran_indexing = check_preference ("do_fortran_indexing"); + Vwarn_fortran_indexing = check_preference ("warn_fortran_indexing"); - liboctave_dfi_flag = Vdo_fortran_indexing; + liboctave_wfi_flag = Vwarn_fortran_indexing; return 0; } @@ -1787,17 +1788,6 @@ } static int -prefer_column_vectors (void) -{ - Vprefer_column_vectors - = check_preference ("prefer_column_vectors"); - - liboctave_pcv_flag = Vprefer_column_vectors; - - return 0; -} - -static int print_answer_id_name (void) { Vprint_answer_id_name = check_preference ("print_answer_id_name"); @@ -1860,35 +1850,6 @@ void symbols_of_ov (void) { - DEFVAR (do_fortran_indexing, false, do_fortran_indexing, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} do_fortran_indexing\n\ -If the value of @code{do_fortran_indexing} is nonzero, Octave allows \n\ -you to select elements of a two-dimensional matrix using a single index\n\ -by treating the matrix as a single vector created from the columns of\n\ -the matrix. The default value is 0. \n\ -@end defvr"); - - DEFVAR (prefer_column_vectors, true, prefer_column_vectors, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} prefer_column_vectors\n\ -If @code{prefer_column_vectors} is nonzero, operations like\n\ -\n\ -@example\n\ -for i = 1:10\n\ - a (i) = i;\n\ -endfor\n\ -@end example\n\ -\n\ -@noindent\n\ -(for @code{a} previously undefined) produce column vectors. Otherwise, row\n\ -vectors are preferred. The default value is 1.\n\ -\n\ -If a variable is already defined to be a vector (a matrix with a single\n\ -row or column), the original orientation is respected, regardless of the\n\ -value of @code{prefer_column_vectors}.\n\ -@end defvr"); - DEFVAR (print_answer_id_name, true, print_answer_id_name, "-*- texinfo -*-\n\ @defvr {Built-in Variable} print_answer_id_name\n\ @@ -1961,6 +1922,14 @@ 0, the warning is omitted. The default value is 1.\n\ @end defvr"); + DEFVAR (warn_fortran_indexing, false, warn_fortran_indexing, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} warn_fortran_indexing\n\ +If the value of @code{warn_fortran_indexing} is nonzero, a warning is\n\ +printed for expressions which select elements of a two-dimensional matrix\n\ +using a single index. The default value is 0.\n\ +@end defvr"); + DEFVAR (warn_imag_to_real, false, warn_imag_to_real, "-*- texinfo -*-\n\ @defvr {Built-in Variable} warn_imag_to_real\n\
--- a/src/ov.h +++ b/src/ov.h @@ -718,12 +718,12 @@ int t::t_id (-1); \ const std::string t::t_name (n) -// If TRUE, allow assignments like +// If TRUE, print a warning for assignments like // // octave> A(1) = 3; A(2) = 5 // // for A already defined and a matrix type. -extern bool Vdo_fortran_indexing; +extern bool Vwarn_fortran_indexing; // Should we print a warning when converting `[97, 98, 99, "123"]' // to a character string?