# HG changeset patch # User jwe # Date 1194366373 0 # Node ID 2c5b14c60c6c6e751ab7d6430a0c5bfc70527123 # Parent 28607462901fccf472a909ac14f2cf8ae901ad75 [project @ 2007-11-06 16:26:13 by jwe] diff --git a/liboctave/MArray-defs.h b/liboctave/MArray-defs.h --- 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); \ diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,9 @@ +2007-11-06 David Bateman + + * linear-algebra/__norm__.m: Scale frobenius norm by infinity norm + to avoid issues of over- and underflow. From Rolf Fabian + . + 2007-11-02 Olli Saarela * time/asctime.m, general/structfun.m: Fix broken @examples in diff --git a/scripts/linear-algebra/__norm__.m b/scripts/linear-algebra/__norm__.m --- 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 diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2007-11-06 John W. Eaton + + * defun-int.h (DEFINE_FUNX_INSTALLER_FUN3): Don't install function + if check_version produces an error. + +2007-11-06 David Bateman + + * MArray-def.h (MARRAY_NORM_BODY): Scale frobenius norm by infinity + norm to avoid issues of over- and underflow. From Rolf Fabian + . + 2007-11-05 John W. Eaton * pt-idx.cc (tree_index_expression::lvalue): Try to do a better diff --git a/src/defun-int.h b/src/defun-int.h --- 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