Mercurial > hg > octave-terminal
changeset 7101:2c5b14c60c6c
[project @ 2007-11-06 16:26:13 by jwe]
author | jwe |
---|---|
date | Tue, 06 Nov 2007 16:26:13 +0000 |
parents | 28607462901f |
children | a627f27c1e8e |
files | liboctave/MArray-defs.h scripts/ChangeLog scripts/linear-algebra/__norm__.m src/ChangeLog src/defun-int.h |
diffstat | 5 files changed, 44 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/MArray-defs.h +++ b/liboctave/MArray-defs.h @@ -358,13 +358,25 @@ /* Frobenius norm. */ \ retval = 0; \ \ + /* precondition */ \ + double inf_norm = 0.; \ for (octave_idx_type i = 0; i < len; i++) \ { \ - double d_abs = std::abs (d[i]); \ + double d_abs = std::abs (d[i]); \ + if (d_abs > inf_norm) \ + inf_norm = d_abs; \ + } \ + inf_norm = (inf_norm == octave_Inf || inf_norm == 0. ? 1.0 : \ + inf_norm); \ + double scale = 1. / inf_norm; \ +\ + for (octave_idx_type i = 0; i < len; i++) \ + { \ + double d_abs = std::abs (d[i]) * scale; \ retval += d_abs * d_abs; \ } \ \ - retval = ::sqrt (retval); \ + retval = ::sqrt (retval) * inf_norm; \ } \ else if (p == 2) \ F77_FCN (blas_norm, BLAS_NORM) (len, d, 1, retval); \
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,9 @@ +2007-11-06 David Bateman <dbateman@free.fr> + + * linear-algebra/__norm__.m: Scale frobenius norm by infinity norm + to avoid issues of over- and underflow. From Rolf Fabian + <Rolf.Fabian@gmx.de>. + 2007-11-02 Olli Saarela <Olli.Saarela@kcl.fi> * time/asctime.m, general/structfun.m: Fix broken @examples in
--- a/scripts/linear-algebra/__norm__.m +++ b/scripts/linear-algebra/__norm__.m @@ -40,11 +40,11 @@ endif ## Do we have a vector or matrix as the first argument? - if (ndims(x) == 2 && (rows (x) == 1 || columns (x) == 1)) if (ischar (p)) if (strcmp (p, "fro")) - retval = sqrt (sum (abs (x) .^ 2)); + inf_norm = norm (x, "inf") + retval = inf_norm .* sqrt (sum (abs (x ./ inf_norm) .^ 2)); elseif (strcmp (p, "inf")) retval = max (abs (x)); else @@ -69,7 +69,8 @@ else if (ischar (p)) if (strcmp (p, "fro")) - retval = sqrt (sum (sum (abs (x) .^ 2))); + inf_norm = norm (x, "inf") + retval = inf_norm .* sqrt (sum (sum (abs (x ./ inf_norm) .^ 2))); elseif (strcmp (p, "inf")) retval = max (sum (abs (x'))); else
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2007-11-06 John W. Eaton <jwe@octave.org> + + * defun-int.h (DEFINE_FUNX_INSTALLER_FUN3): Don't install function + if check_version produces an error. + +2007-11-06 David Bateman <dbateman@free.fr> + + * MArray-def.h (MARRAY_NORM_BODY): Scale frobenius norm by infinity + norm to avoid issues of over- and underflow. From Rolf Fabian + <Rolf.Fabian@gmx.de>. + 2007-11-05 John W. Eaton <jwe@octave.org> * pt-idx.cc (tree_index_expression::lvalue): Try to do a better
--- a/src/defun-int.h +++ b/src/defun-int.h @@ -95,9 +95,16 @@ bool \ fsname ## _ ## cxx_abi (const octave_shlib& shl, bool relative) \ { \ + bool retval = true; \ + \ check_version (OCTAVE_API_VERSION, name); \ - install_dld_function (fname, name, shl, doc, false, relative); \ - return error_state ? false : true; \ + \ + if (error_state) \ + retval = false; \ + else \ + install_dld_function (fname, name, shl, doc, false, relative); \ + \ + return retval; \ } // MAKE_BUILTINS is defined to extract function names and related