« Return to Thread: Bug+patch: norm(X, "fro") fails when X has zero norm

Bug+patch: norm(X, "fro") fails when X has zero norm

by jfc :: Rate this Message:

Reply to Author | View in Thread

Hello all,

here is a simple patch for a bug introduced around 2.9.16

Bug:   norm(zeros(3), "fro") returns "NaN" and raises a warning.

The obvious patch to __norm__.m  and Changelog is attached.

Congrats on 3.0 !

Cheers, JF


*** scripts/linear-algebra/__norm__.m Wed Nov  7 18:38:29 2007
--- scripts/linear-algebra/__norm__fixed.m Sun Dec 30 20:01:35 2007
***************
*** 70,76 ****
      if (ischar (p))
        if (strcmp (p, "fro"))
          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
--- 70,80 ----
      if (ischar (p))
        if (strcmp (p, "fro"))
          inf_norm = norm (x, "inf");
! if (inf_norm==0)
!  retval = 0 ;
! else
!  retval = inf_norm .* sqrt (sum (sum (abs (x ./ inf_norm) .^ 2)));
! endif
        elseif (strcmp (p, "inf"))
          retval = max (sum (abs (x')));
        else


*** scripts/ChangeLog.~1.1124.~ Sun Dec 30 19:54:46 2007
--- scripts/ChangeLog Sun Dec 30 20:16:53 2007
***************
*** 1,3 ****
--- 1,8 ----
+ 2007-12-31  Jean-Francois Cardoso  <cardoso@enst.fr>
+
+ * linear-algebra/__norm__.m: norm(X, "fro") now works even if X is
+ a zero matrix.
+
  2007-12-28  John W. Eaton  <jwe@octave.org>
 
  * miscellaneous/edit.m: Use strcat instead of fullfile to add file





 « Return to Thread: Bug+patch: norm(X, "fro") fails when X has zero norm