Mercurial > hg > octave-avbm
changeset 3480:45742a3b1f7c
[project @ 2000-01-26 06:16:41 by jwe]
author | jwe |
---|---|
date | Wed, 26 Jan 2000 06:16:44 +0000 |
parents | 19e0f69da41e |
children | d964028659fb |
files | liboctave/CMatrix.cc liboctave/CMatrix.h liboctave/ChangeLog liboctave/dMatrix.cc liboctave/dMatrix.h readline/rltty.c src/ChangeLog src/lex.l src/octave.cc src/xdiv.cc |
diffstat | 10 files changed, 197 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- 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 {
--- a/liboctave/CMatrix.h +++ b/liboctave/CMatrix.h @@ -47,6 +47,8 @@ public: + typedef void (*solve_singularity_handler) (double rcond); + ComplexMatrix (void) : MArray2<Complex> () { } ComplexMatrix (int r, int c) : MArray2<Complex> (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;
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,5 +1,13 @@ 2000-01-25 John W. Eaton <jwe@bevo.che.wisc.edu> + * 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.
--- 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 {
--- a/liboctave/dMatrix.h +++ b/liboctave/dMatrix.h @@ -51,6 +51,8 @@ public: + typedef void (*solve_singularity_handler) (double rcond); + Matrix (void) : MArray2<double> () { } Matrix (int r, int c) : MArray2<double> (r, c) { } Matrix (int r, int c, double val) : MArray2<double> (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;
--- 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 ();
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2000-01-25 John W. Eaton <jwe@bevo.che.wisc.edu> + * 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'.
--- 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.
--- 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 ();
--- 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 <class T1, class T2> @@ -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; }