# HG changeset patch # User jwe # Date 948867404 0 # Node ID 45742a3b1f7cfff1621342b9b3b027e9cd36c3f5 # Parent 19e0f69da41e49b5d924d70fd48f25d60e35eed0 [project @ 2000-01-26 06:16:41 by jwe] diff --git a/liboctave/CMatrix.cc b/liboctave/CMatrix.cc --- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -918,7 +918,7 @@ { ComplexMatrix retval; - ComplexSVD result (*this); + ComplexSVD result (*this, SVD::economy); DiagMatrix S = result.singular_values (); ComplexMatrix U = result.left_singular_matrix (); @@ -1233,21 +1233,28 @@ { int info; double rcond; - return solve (b, info, rcond); + return solve (b, info, rcond, 0); } ComplexMatrix ComplexMatrix::solve (const Matrix& b, int& info) const { double rcond; - return solve (b, info, rcond); + return solve (b, info, rcond, 0); } ComplexMatrix ComplexMatrix::solve (const Matrix& b, int& info, double& rcond) const { + return solve (b, info, rcond, 0); +} + +ComplexMatrix +ComplexMatrix::solve (const Matrix& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const +{ ComplexMatrix tmp (b); - return solve (tmp, info, rcond); + return solve (tmp, info, rcond, sing_handler); } ComplexMatrix @@ -1255,18 +1262,26 @@ { int info; double rcond; - return solve (b, info, rcond); + return solve (b, info, rcond, 0); } ComplexMatrix ComplexMatrix::solve (const ComplexMatrix& b, int& info) const { double rcond; - return solve (b, info, rcond); + return solve (b, info, rcond, 0); } + ComplexMatrix ComplexMatrix::solve (const ComplexMatrix& b, int& info, double& rcond) const { + return solve (b, info, rcond, 0); +} + +ComplexMatrix +ComplexMatrix::solve (const ComplexMatrix& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const +{ ComplexMatrix retval; int nr = rows (); @@ -1299,6 +1314,13 @@ if (rcond_plus_one == 1.0) { info = -2; + + if (sing_handler) + sing_handler (rcond); + else + (*current_liboctave_error_handler) + ("matrix singular to machine precision, rcond = %g", + rcond); } else { @@ -1332,20 +1354,28 @@ { int info; double rcond; - return solve (b, info, rcond); + return solve (b, info, rcond, 0); } ComplexColumnVector ComplexMatrix::solve (const ComplexColumnVector& b, int& info) const { double rcond; - return solve (b, info, rcond); + return solve (b, info, rcond, 0); } ComplexColumnVector ComplexMatrix::solve (const ComplexColumnVector& b, int& info, double& rcond) const { + return solve (b, info, rcond, 0); +} + +ComplexColumnVector +ComplexMatrix::solve (const ComplexColumnVector& b, int& info, + double& rcond, + solve_singularity_handler sing_handler) const +{ ComplexColumnVector retval; int nr = rows (); @@ -1379,6 +1409,13 @@ if (rcond_plus_one == 1.0) { info = -2; + + if (sing_handler) + sing_handler (rcond); + else + (*current_liboctave_error_handler) + ("matrix singular to machine precision, rcond = %g", + rcond); } else { diff --git a/liboctave/CMatrix.h b/liboctave/CMatrix.h --- a/liboctave/CMatrix.h +++ b/liboctave/CMatrix.h @@ -47,6 +47,8 @@ public: + typedef void (*solve_singularity_handler) (double rcond); + ComplexMatrix (void) : MArray2 () { } ComplexMatrix (int r, int c) : MArray2 (r, c) { } ComplexMatrix (int r, int c, const Complex& val) @@ -150,15 +152,22 @@ ComplexMatrix solve (const Matrix& b) const; ComplexMatrix solve (const Matrix& b, int& info) const; ComplexMatrix solve (const Matrix& b, int& info, double& rcond) const; + ComplexMatrix solve (const Matrix& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const; ComplexMatrix solve (const ComplexMatrix& b) const; ComplexMatrix solve (const ComplexMatrix& b, int& info) const; ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; + ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const; ComplexColumnVector solve (const ComplexColumnVector& b) const; ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; ComplexColumnVector solve (const ComplexColumnVector& b, int& info, double& rcond) const; + ComplexColumnVector solve (const ComplexColumnVector& b, int& info, + double& rcond, + solve_singularity_handler sing_handler) const; ComplexMatrix lssolve (const ComplexMatrix& b) const; ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,5 +1,13 @@ 2000-01-25 John W. Eaton + * dMatrix.cc (Matrix::solve (...)): Add new variant with + function pointer as final arg. Passed function (if any) will be + called for singularity errors. + * CMatrix.cc (ComplexMatrix::solve (...)): Likewise. + + * dMatrix.cc (Matrix::pseudo_inverse): Use economy SVD. + * CMatrix.cc (ComplexMatrix::pseudo_inverse): Likewise. + * lo-ieee.cc (octave_ieee_init): Don't include sunmath.h. No longer bother with infinity or quiet_nan. diff --git a/liboctave/dMatrix.cc b/liboctave/dMatrix.cc --- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -612,7 +612,7 @@ Matrix Matrix::pseudo_inverse (double tol) { - SVD result (*this); + SVD result (*this, SVD::economy); DiagMatrix S = result.singular_values (); Matrix U = result.left_singular_matrix (); @@ -938,6 +938,13 @@ Matrix Matrix::solve (const Matrix& b, int& info, double& rcond) const { + return solve (b, info, rcond, 0); +} + +Matrix +Matrix::solve (const Matrix& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const +{ Matrix retval; int nr = rows (); @@ -970,6 +977,13 @@ if (rcond_plus_one == 1.0) { info = -2; + + if (sing_handler) + sing_handler (rcond); + else + (*current_liboctave_error_handler) + ("matrix singular to machine precision, rcond = %g", + rcond); } else { @@ -1019,6 +1033,14 @@ return tmp.solve (b, info, rcond); } +ComplexMatrix +Matrix::solve (const ComplexMatrix& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const +{ + ComplexMatrix tmp (*this); + return tmp.solve (b, info, rcond, sing_handler); +} + ColumnVector Matrix::solve (const ColumnVector& b) const { @@ -1036,6 +1058,13 @@ ColumnVector Matrix::solve (const ColumnVector& b, int& info, double& rcond) const { + return solve (b, info, rcond, 0); +} + +ColumnVector +Matrix::solve (const ColumnVector& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const +{ ColumnVector retval; int nr = rows (); @@ -1069,6 +1098,13 @@ if (rcond_plus_one == 1.0) { info = -2; + + if (sing_handler) + sing_handler (rcond); + else + (*current_liboctave_error_handler) + ("matrix singular to machine precision, rcond = %g", + rcond); } else { @@ -1108,6 +1144,14 @@ return tmp.solve (b, info, rcond); } +ComplexColumnVector +Matrix::solve (const ComplexColumnVector& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const +{ + ComplexMatrix tmp (*this); + return tmp.solve (b, info, rcond, sing_handler); +} + Matrix Matrix::lssolve (const Matrix& b) const { diff --git a/liboctave/dMatrix.h b/liboctave/dMatrix.h --- a/liboctave/dMatrix.h +++ b/liboctave/dMatrix.h @@ -51,6 +51,8 @@ public: + typedef void (*solve_singularity_handler) (double rcond); + Matrix (void) : MArray2 () { } Matrix (int r, int c) : MArray2 (r, c) { } Matrix (int r, int c, double val) : MArray2 (r, c, val) { } @@ -131,19 +133,28 @@ Matrix solve (const Matrix& b) const; Matrix solve (const Matrix& b, int& info) const; Matrix solve (const Matrix& b, int& info, double& rcond) const; + Matrix solve (const Matrix& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const; ComplexMatrix solve (const ComplexMatrix& b) const; ComplexMatrix solve (const ComplexMatrix& b, int& info) const; ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; + ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const; ColumnVector solve (const ColumnVector& b) const; ColumnVector solve (const ColumnVector& b, int& info) const; ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const; + ColumnVector solve (const ColumnVector& b, int& info, double& rcond, + solve_singularity_handler sing_handler) const; ComplexColumnVector solve (const ComplexColumnVector& b) const; ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; ComplexColumnVector solve (const ComplexColumnVector& b, int& info, double& rcond) const; + ComplexColumnVector solve (const ComplexColumnVector& b, int& info, + double& rcond, + solve_singularity_handler sing_handler) const; Matrix lssolve (const Matrix& b) const; Matrix lssolve (const Matrix& b, int& info) const; diff --git a/readline/rltty.c b/readline/rltty.c --- a/readline/rltty.c +++ b/readline/rltty.c @@ -154,7 +154,11 @@ struct winsize w; if (ioctl (tty, TIOCGWINSZ, &w) == 0) + { + fprintf (stderr, "setting window size: %d x %d\n", w.ws_row, w.ws_col); + (void) ioctl (tty, TIOCSWINSZ, &w); + } } #else /* SHELL || !TIOCGWINSZ */ # define set_winsize(tty) @@ -533,6 +537,8 @@ tty = fileno (rl_instream); + fprintf (stderr, "rl_prep_terminal\n"); + if (get_tty_settings (tty, &tio) < 0) { release_sigint (); diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2000-01-25 John W. Eaton + * xdiv.cc (result_ok): Just check value of info. + (solve_singularity_warning): New function. + (xleftdiv, xdiv): Pass pointer to solve_singularity_warning to + solve function. + + * lex.l (handle_identifier): Set next_tok_is_eq if we are looking + at `=', but not if we are looking at `=='. + * pt-pr-code.cc (tree_print_code::visit_unwind_protect_command): Print `unwind_protect_cleanup', not `cleanup_code'. diff --git a/src/lex.l b/src/lex.l --- a/src/lex.l +++ b/src/lex.l @@ -2050,11 +2050,22 @@ TOK_RETURN (plot_option_kw); } - int c = yyinput (); - unput (c); - bool next_tok_is_eq = (c == '='); - bool next_tok_is_dot = (c == '.'); - bool next_tok_is_paren = (c == '('); + int c1 = yyinput (); + + bool next_tok_is_dot = (c1 == '.'); + bool next_tok_is_paren = (c1 == '('); + + bool next_tok_is_eq = false; + if (c1 == '=') + { + int c2 = yyinput (); + unput (c2); + + if (c2 != '=') + next_tok_is_eq = true; + } + + unput (c1); // Make sure we put the return values of a function in the symbol // table that is local to the function. diff --git a/src/octave.cc b/src/octave.cc --- a/src/octave.cc +++ b/src/octave.cc @@ -373,6 +373,7 @@ initialize_pathsearch (); + cerr << "installing octave signal handlers\n"; install_signal_handlers (); initialize_file_io (); diff --git a/src/xdiv.cc b/src/xdiv.cc --- a/src/xdiv.cc +++ b/src/xdiv.cc @@ -33,22 +33,18 @@ #include "error.h" #include "xdiv.h" -static inline int -result_ok (int info, double rcond, int warn = 1) +static inline bool +result_ok (int info) { assert (info != -1); - if (info == -2) - { - if (warn) - warning ("matrix singular to machine precision, rcond = %g", rcond); - else - error ("matrix singular to machine precision, rcond = %g", rcond); + return (info != -2); +} - return 0; - } - else - return 1; +static void +solve_singularity_warning (double rcond) +{ + warning ("matrix singular to machine precision, rcond = %g", rcond); } template @@ -128,8 +124,11 @@ if (btmp.rows () == btmp.columns ()) { double rcond = 0.0; - Matrix result = btmp.solve (atmp, info, rcond); - if (result_ok (info, rcond)) + + Matrix result + = btmp.solve (atmp, info, rcond, solve_singularity_warning); + + if (result_ok (info)) return Matrix (result.transpose ()); } @@ -153,8 +152,11 @@ if (btmp.rows () == btmp.columns ()) { double rcond = 0.0; - ComplexMatrix result = btmp.solve (atmp, info, rcond); - if (result_ok (info, rcond)) + + ComplexMatrix result + = btmp.solve (atmp, info, rcond, solve_singularity_warning); + + if (result_ok (info)) return result.hermitian (); } @@ -178,8 +180,11 @@ if (btmp.rows () == btmp.columns ()) { double rcond = 0.0; - ComplexMatrix result = btmp.solve (atmp, info, rcond); - if (result_ok (info, rcond)) + + ComplexMatrix result + = btmp.solve (atmp, info, rcond, solve_singularity_warning); + + if (result_ok (info)) return result.hermitian (); } @@ -203,8 +208,11 @@ if (btmp.rows () == btmp.columns ()) { double rcond = 0.0; - ComplexMatrix result = btmp.solve (atmp, info, rcond); - if (result_ok (info, rcond)) + + ComplexMatrix result + = btmp.solve (atmp, info, rcond, solve_singularity_warning); + + if (result_ok (info)) return result.hermitian (); } @@ -303,8 +311,11 @@ if (a.rows () == a.columns ()) { double rcond = 0.0; - Matrix result = a.solve (b, info, rcond); - if (result_ok (info, rcond)) + + Matrix result + = a.solve (b, info, rcond, solve_singularity_warning); + + if (result_ok (info)) return result; } @@ -323,8 +334,11 @@ if (a.rows () == a.columns ()) { double rcond = 0.0; - ComplexMatrix result = a.solve (b, info, rcond); - if (result_ok (info, rcond)) + + ComplexMatrix result + = a.solve (b, info, rcond, solve_singularity_warning); + + if (result_ok (info)) return result; } @@ -343,8 +357,11 @@ if (a.rows () == a.columns ()) { double rcond = 0.0; - ComplexMatrix result = a.solve (b, info, rcond); - if (result_ok (info, rcond)) + + ComplexMatrix result + = a.solve (b, info, rcond, solve_singularity_warning); + + if (result_ok (info)) return result; } @@ -363,8 +380,11 @@ if (a.rows () == a.columns ()) { double rcond = 0.0; - ComplexMatrix result = a.solve (b, info, rcond); - if (result_ok (info, rcond)) + + ComplexMatrix result + = a.solve (b, info, rcond, solve_singularity_warning); + + if (result_ok (info)) return result; }