# HG changeset patch # User jwe # Date 1059592531 0 # Node ID 7afd4bf05aa8c742b71362bcbff9133db4b70118 # Parent 87c2e107f8117a726b5bda965a6b41c9412c99f9 [project @ 2003-07-30 19:15:31 by jwe] diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2003-07-30 John W. Eaton + * emacs/octave-mod.el (octave-variables): Delete + propagate_empty_matrices from the list. + * ck-oct-fcns.m: Delete. 2003-07-25 John W. Eaton diff --git a/doc/interpreter/numbers.txi b/doc/interpreter/numbers.txi --- a/doc/interpreter/numbers.txi +++ b/doc/interpreter/numbers.txi @@ -331,8 +331,6 @@ list to determine whether they are all constants. If they are, it replaces the list with a single matrix constant. -@DOCSTRING(propagate_empty_matrices) - @node Ranges @section Ranges @cindex range expressions diff --git a/emacs/octave-mod.el b/emacs/octave-mod.el --- a/emacs/octave-mod.el +++ b/emacs/octave-mod.el @@ -147,7 +147,7 @@ "inf" "nan" "nargin" "output_max_field_width" "output_precision" "page_output_immediately" "page_screen_output" "pi" "print_answer_id_name" "print_empty_dimensions" - "program_invocation_name" "program_name" "propagate_empty_matrices" + "program_invocation_name" "program_name" "realmax" "realmin" "return_last_computed_value" "save_precision" "saving_history" "sighup_dumps_octave_core" "sigterm_dumps_octave_core" "silent_functions" "split_long_rows" "stderr" "stdin" "stdout" diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2003-07-30 Heine Kolltveit + + * mx-base.h: Include ArrayN.h. + 2003-30-07 Heine Kolltveit * ArrayN.cc (operator <<): Corrected output. diff --git a/liboctave/mx-base.h b/liboctave/mx-base.h --- a/liboctave/mx-base.h +++ b/liboctave/mx-base.h @@ -45,6 +45,10 @@ #include "dDiagMatrix.h" #include "CDiagMatrix.h" +// N-dimensional Array classes. + +#include "ArrayN.h" + #endif /* diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,8 +1,13 @@ 2003-07-30 John W. Eaton + * linear-algebra/cond.m: Behave as though old built-in variable + propagate_empty_matrices is always 1. Also handle empty matrices + with one non-zero dimension. + * miscellaneous/dump_prefs.m: Add warn_separator_insert and warn_single_quote_string to the list. - Delete whitespace_in_literal_matrix from the list. + Delete whitespace_in_literal_matrix and propagate_empty_matrices + from the list. 2003-07-25 Paul Kienzle diff --git a/scripts/linear-algebra/cond.m b/scripts/linear-algebra/cond.m --- a/scripts/linear-algebra/cond.m +++ b/scripts/linear-algebra/cond.m @@ -31,13 +31,7 @@ if (nargin == 1) [nr, nc] = size (a); - if (nr == 0 && nc == 0) - if (! propagate_empty_matrices) - error ("cond: empty matrix is invalid as argument"); - endif - if (strcmp (propagate_empty_matrices, "warn")) - warning ("cond: argument is empty matrix\n"); - endif + if (nr == 0 || nc == 0) retval = 0.0; endif if (any (any (isinf (a) | isnan (a)))) diff --git a/scripts/miscellaneous/dump_prefs.m b/scripts/miscellaneous/dump_prefs.m --- a/scripts/miscellaneous/dump_prefs.m +++ b/scripts/miscellaneous/dump_prefs.m @@ -76,7 +76,6 @@ "print_answer_id_name"; "print_empty_dimensions"; "print_rhs_assign_val"; - "propagate_empty_matrices"; "return_last_computed_value"; "save_precision"; "saving_history"; diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,14 +1,42 @@ 2003-07-30 John W. Eaton + * utils.cc (identity_matrix): Move here from data.cc. + (identity_matrix): Use std::min instead of our own MIN macro. + + * utils.h (identity_matrix): Provide decl. + + * DLD-FUNCTIONS/svd.cc (Fsvd): Improve handling of empty matrix arg. + + * ov.cc (octave_value(const ArrayN&)): New constructor. + * ov.h (octave_value(const ArrayN&)): Provide decl. + +2003-07-30 Heine Kolltveit + + * ov.cc (octave_value(const ArrayN&)): New constructor. + * ov.h (octave_value(const ArrayN&)): Provide decl. + +2003-07-30 John W. Eaton + + * ov.h (Vpropagate_empty_matrices): Delete decl. + * ov.cc: (Vpropagate_empty_matrices): Delete. + (propagate_empty_matrices): Delete. + (symbols_of_ov): Delete DEFVAR for propagate_empty_matrices. + + * utils.cc (empty_arg): Behave as though propagate_empty_matrices + is always 1. + * ov-range.cc (octave_range::is_true): Likewise. + * ov-base-mat.cc (octave_base_matrix::is_true): Likewise. + * octave.cc (maximum_braindamage): Also set warn_matlab_incompatible to TRUE. - * lex.l (whitespace_in_literal_matrix): Delete. + * lex.l (Vwhitespace_in_literal_matrix): Delete. + (whitespace_in_literal_matrix): Delete. (symbols_of_lex): Delete DEFVAR for whitespace_in_literal_matrix. ({S}*\,{S}*, {S}+, ({S}*{COMMENT}{SNLCMT}*, {S}*{NL}{SNLCMT}*, maybe_unput_comma): Behave as though - Vwhitespace_in_literal_matrix is always 1. + old Vwhitespace_in_literal_matrix varaible is always 1. * octave.cc (maximum_braindamage): Don't set whitespace_in_literal_matrix. diff --git a/src/DLD-FUNCTIONS/svd.cc b/src/DLD-FUNCTIONS/svd.cc --- a/src/DLD-FUNCTIONS/svd.cc +++ b/src/DLD-FUNCTIONS/svd.cc @@ -128,79 +128,87 @@ octave_value arg = args(0); - int arg_is_empty = empty_arg ("svd", arg.rows (), arg.columns ()); - - if (arg_is_empty < 0) - return retval; - else if (arg_is_empty > 0) - return octave_value_list (3, Matrix ()); - - SVD::type type = ((nargout == 0 || nargout == 1) - ? SVD::sigma_only - : (nargin == 2) ? SVD::economy : SVD::std); - - if (arg.is_real_type ()) - { - Matrix tmp = arg.matrix_value (); - - if (! error_state) - { - if (tmp.any_element_is_inf_or_nan ()) - { - error ("svd: cannot take SVD of matrix containing Inf or\ - NaN values"); - return retval; - } - - SVD result (tmp, type); - - DiagMatrix sigma = result.singular_values (); + int nr = arg.rows (); + int nc = arg.columns (); - if (nargout == 0 || nargout == 1) - { - retval(0) = sigma.diag (); - } - else - { - retval(2) = result.right_singular_matrix (); - retval(1) = sigma; - retval(0) = result.left_singular_matrix (); - } - } - } - else if (arg.is_complex_type ()) + if (nr == 0 || nc == 0) { - ComplexMatrix ctmp = arg.complex_matrix_value (); - - if (! error_state) + if (nargout == 3) { - if (ctmp.any_element_is_inf_or_nan ()) - { - error ("svd: cannot take SVD of matrix containing Inf or\ - NaN values"); - return retval; - } - - ComplexSVD result (ctmp, type); - - DiagMatrix sigma = result.singular_values (); - - if (nargout == 0 || nargout == 1) - { - retval(0) = sigma.diag (); - } - else - { - retval(2) = result.right_singular_matrix (); - retval(1) = sigma; - retval(0) = result.left_singular_matrix (); - } + retval(3) = identity_matrix (nr, nr); + retval(2) = Matrix (nr, nc); + retval(1) = identity_matrix (nc, nc); } + else + retval(0) = Matrix (0, 1); } else { - gripe_wrong_type_arg ("svd", arg); - return retval; + SVD::type type = ((nargout == 0 || nargout == 1) + ? SVD::sigma_only + : (nargin == 2) ? SVD::economy : SVD::std); + + if (arg.is_real_type ()) + { + Matrix tmp = arg.matrix_value (); + + if (! error_state) + { + if (tmp.any_element_is_inf_or_nan ()) + { + error ("svd: cannot take SVD of matrix containing Inf or NaN values"); + return retval; + } + + SVD result (tmp, type); + + DiagMatrix sigma = result.singular_values (); + + if (nargout == 0 || nargout == 1) + { + retval(0) = sigma.diag (); + } + else + { + retval(2) = result.right_singular_matrix (); + retval(1) = sigma; + retval(0) = result.left_singular_matrix (); + } + } + } + else if (arg.is_complex_type ()) + { + ComplexMatrix ctmp = arg.complex_matrix_value (); + + if (! error_state) + { + if (ctmp.any_element_is_inf_or_nan ()) + { + error ("svd: cannot take SVD of matrix containing Inf or NaN values"); + return retval; + } + + ComplexSVD result (ctmp, type); + + DiagMatrix sigma = result.singular_values (); + + if (nargout == 0 || nargout == 1) + { + retval(0) = sigma.diag (); + } + else + { + retval(2) = result.right_singular_matrix (); + retval(1) = sigma; + retval(0) = result.left_singular_matrix (); + } + } + } + else + { + gripe_wrong_type_arg ("svd", arg); + return retval; + } } return retval; diff --git a/src/data.cc b/src/data.cc --- a/src/data.cc +++ b/src/data.cc @@ -999,21 +999,6 @@ return fill_matrix (args, 0.0, "zeros"); } -static Matrix -identity_matrix (int nr, int nc) -{ - Matrix m (nr, nc, 0.0); - - if (nr > 0 && nc > 0) - { - int n = MIN (nr, nc); - for (int i = 0; i < n; i++) - m (i, i) = 1.0; - } - - return m; -} - DEFUN (eye, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} eye (@var{x})\n\ diff --git a/src/ov-base-mat.cc b/src/ov-base-mat.cc --- a/src/ov-base-mat.cc +++ b/src/ov-base-mat.cc @@ -198,16 +198,7 @@ { bool retval = false; - if (rows () == 0 || columns () == 0) - { - int flag = Vpropagate_empty_matrices; - - if (flag < 0) - warning ("empty matrix used in conditional expression"); - else if (flag == 0) - error ("empty matrix used in conditional expression"); - } - else + if (rows () > 0 && columns () > 0) { boolMatrix m = (matrix.all () . all ()); diff --git a/src/ov-range.cc b/src/ov-range.cc --- a/src/ov-range.cc +++ b/src/ov-range.cc @@ -172,16 +172,7 @@ { bool retval = false; - if (range.nelem () == 0) - { - int flag = Vpropagate_empty_matrices; - - if (flag < 0) - warning ("empty range used in conditional expression"); - else if (flag == 0) - error ("empty range used in conditional expression"); - } - else + if (range.nelem () != 0) { // XXX FIXME XXX -- this is a potential waste of memory. diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -99,12 +99,6 @@ // If TRUE, print the name along with the value. bool Vprint_answer_id_name; -// Should operations on empty matrices return empty matrices or an -// error? A positive value means yes. A negative value means yes, -// but print a warning message. Zero means it should be considered an -// error. -int Vpropagate_empty_matrices; - // How many levels of structure elements should we print? int Vstruct_levels_to_print; @@ -413,6 +407,13 @@ maybe_mutate (); } +octave_value::octave_value (const ArrayN& a) + : rep (new octave_double_nd_array (a)) +{ + rep->count = 1; + maybe_mutate (); +} + octave_value::octave_value (const DiagMatrix& d) : rep (new octave_matrix (d)) { @@ -448,6 +449,15 @@ maybe_mutate (); } +#if 0 +octave_value::octave_value (const ArrayN& a) + : rep (new octave_complex_nd_array (a)) +{ + rep->count = 1; + maybe_mutate (); +} +#endif + octave_value::octave_value (const ComplexDiagMatrix& d) : rep (new octave_complex_matrix (d)) { @@ -1796,14 +1806,6 @@ } static int -propagate_empty_matrices (void) -{ - Vpropagate_empty_matrices = check_preference ("propagate_empty_matrices"); - - return 0; -} - -static int warn_resize_on_range_error (void) { Vwarn_resize_on_range_error @@ -1859,14 +1861,6 @@ values are printed. The default value is 1.\n\ @end defvr"); - DEFVAR (propagate_empty_matrices, true, propagate_empty_matrices, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} propagate_empty_matrices\n\ -If the value of @code{propagate_empty_matrices} is nonzero,\n\ -functions like @code{inverse} and @code{svd} will return an empty matrix\n\ -if they are given one as an argument. The default value is 1.\n\ -@end defvr"); - DEFVAR (silent_functions, false, silent_functions, "-*- texinfo -*-\n\ @defvr {Built-in Variable} silent_functions\n\ diff --git a/src/ov.h b/src/ov.h --- a/src/ov.h +++ b/src/ov.h @@ -183,11 +183,13 @@ octave_value (double d); octave_value (const Cell& m); octave_value (const Matrix& m); + octave_value (const ArrayN& m); octave_value (const DiagMatrix& d); octave_value (const RowVector& v); octave_value (const ColumnVector& v); octave_value (const Complex& C); octave_value (const ComplexMatrix& m); + octave_value (const ArrayN& m); octave_value (const ComplexDiagMatrix& d); octave_value (const ComplexRowVector& v); octave_value (const ComplexColumnVector& v); @@ -744,12 +746,6 @@ // If TRUE, print the name along with the value. extern bool Vprint_answer_id_name; -// Should operations on empty matrices return empty matrices or an -// error? A positive value means yes. A negative value means yes, -// but print a warning message. Zero means it should be considered an -// error. -extern int Vpropagate_empty_matrices; - // How many levels of structure elements should we print? extern int Vstruct_levels_to_print; diff --git a/src/utils.cc b/src/utils.cc --- a/src/utils.cc +++ b/src/utils.cc @@ -229,27 +229,7 @@ int empty_arg (const char *name, int nr, int nc) { - int is_empty = 0; - - if (nr == 0 || nc == 0) - { - int flag = Vpropagate_empty_matrices; - - if (flag < 0) - { - gripe_empty_arg (name, 0); - is_empty = 1; - } - else if (flag == 0) - { - gripe_empty_arg (name, 1); - is_empty = -1; - } - else - is_empty = 1; - } - - return is_empty; + return (nr == 0 || nc == 0); } // See if the given file is in the path. @@ -828,6 +808,22 @@ check_dimensions (nr, nc, warn_for); // May set error_state. } +Matrix +identity_matrix (int nr, int nc) +{ + Matrix m (nr, nc, 0.0); + + if (nr > 0 && nc > 0) + { + int n = std::min (nr, nc); + + for (int i = 0; i < n; i++) + m (i, i) = 1.0; + } + + return m; +} + extern int octave_format (std::ostream& os, const char *fmt, ...) { diff --git a/src/utils.h b/src/utils.h --- a/src/utils.h +++ b/src/utils.h @@ -28,6 +28,7 @@ #include #include +#include "dMatrix.h" #include "lo-utils.h" class octave_value; @@ -73,6 +74,8 @@ get_dimensions (const octave_value& a, const char *warn_for, int& nr, int& nc); +extern Matrix identity_matrix (int nr, int nc); + extern int octave_format (std::ostream& os, const char *fmt, ...); diff --git a/test/octave.test/prefer/prefer-23.m b/test/octave.test/prefer/prefer-23.m --- a/test/octave.test/prefer/prefer-23.m +++ b/test/octave.test/prefer/prefer-23.m @@ -1,2 +1,1 @@ -propagate_empty_matrices = 0; inv ([]) == [] diff --git a/test/octave.test/prefer/prefer-24.m b/test/octave.test/prefer/prefer-24.m --- a/test/octave.test/prefer/prefer-24.m +++ b/test/octave.test/prefer/prefer-24.m @@ -1,2 +1,1 @@ -propagate_empty_matrices = 1; -inv ([]) == [] +all (svd ([]) == zeros (0, 1)) diff --git a/test/octave.test/prefer/prefer.exp b/test/octave.test/prefer/prefer.exp --- a/test/octave.test/prefer/prefer.exp +++ b/test/octave.test/prefer/prefer.exp @@ -94,12 +94,10 @@ set prog_output "[](3x0)" do_test prefer-22.m -## propagate_empty_matrices - -## This should maybe test more functions... +## These tests maybe don't belong here now... set test propagate-empty-matrices-1 -set prog_output "^error:.*" +set prog_output "^ans = 1" do_test prefer-23.m set test propagate-empty-matrices-2