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

jfc rajif at free.fr
Sun Dec 30 13:35:38 CST 2007


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 at 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 at octave.org>
  
  	* miscellaneous/edit.m: Use strcat instead of fullfile to add file






-- 
View this message in context: http://www.nabble.com/Bug%2Bpatch%3A--norm%28X%2C-%22fro%22%29-fails-when-X-has-zero-norm-tp14550359p14550359.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.



More information about the Octave-maintainers mailing list