# HG changeset patch
# User Juan Pablo Carbajal <carbajal@gmail.com>
# Date 1320776222 -3600
# Branch stable
# Node ID 822244b076ac078c59eb86946042ec7151f74c23
# Parent  5289d7c2460db8c55912320ce8a0f56a9e44c9bc
Fixing bug in norm when 3 arguments given

diff -r 5289d7c2460d -r 822244b076ac src/data.cc
--- a/src/data.cc	Wed Nov 02 20:50:20 2011 -0700
+++ b/src/data.cc	Tue Nov 08 19:17:02 2011 +0100
@@ -4823,17 +4823,30 @@
 
           if (! error_state)
             {
-              octave_value p_arg = (nargin > 1) ? args(1) : octave_value (2);
+              octave_value p_arg;
+              if (nargin > 1 && args(nargin-1).is_string ())
+              {
+                std::string str = args(nargin-1).string_value ();
+                if (str == "fro")
+                  p_arg = octave_value (2);
+                else if (str == "inf")
+                  error ("norm: Inf not yet implemented for cols/rows");
+              }
+              else if (nargin > 1)
+                p_arg = args(1);
+              else
+                p_arg = octave_value (2);
+
               switch (strflag)
                 {
                 case sfmatrix:
                   retval(0) = xnorm (x_arg, p_arg);
                   break;
                 case sfcols:
-                  retval(0) = xcolnorms (x_arg, p_arg);
+                    retval(0) = xcolnorms (x_arg, p_arg);
                   break;
                 case sfrows:
-                  retval(0) = xrownorms (x_arg, p_arg);
+                    retval(0) = xrownorms (x_arg, p_arg);
                   break;
                 case sffrob:
                   retval(0) = xfrobnorm (x_arg);
@@ -4903,6 +4916,16 @@
 %! fhi = single(1e+300);
 %!assert (norm(flo*m2,"fro"), single(sqrt(30)*flo), -eps('single'))
 %!assert (norm(fhi*m2,"fro"), single(sqrt(30)*fhi), -eps('single'))
+
+%!shared q
+%! q = rand(1e3,3);
+%!assert(norm(q,3,"rows") ,sum(q.^3,2).^(1/3),sqrt(eps));
+%!assert(norm(q,"fro","rows") ,sum(q.^2,2).^(1/2),sqrt(eps));
+%!assert(norm(q,"fro","rows") ,sqrt(sumsq(q,2)),sqrt(eps));
+%!assert(norm(q,"fro","cols") ,sqrt(sumsq(q,1)),sqrt(eps));
+%!assert(norm(q,3,"cols") ,sum(q.^3,1).^(1/3),sqrt(eps));
+%!error <Inf not yet implemented> norm(q,"Inf","row");
+%!error <Inf not yet implemented> norm(q,"Inf","cols");
 */
 
 static octave_value
# HG changeset patch
# User Juan Pablo Carbajal <carbajal@gmail.com>
# Date 1320776222 -3600
# Branch stable
# Node ID 708e4224c424b3219c9e5c957bca9e019b9a96aa
# Parent  5289d7c2460db8c55912320ce8a0f56a9e44c9bc
Fixing bug in norm when 3 arguments given

diff -r 5289d7c2460d -r 708e4224c424 src/data.cc
--- a/src/data.cc	Wed Nov 02 20:50:20 2011 -0700
+++ b/src/data.cc	Tue Nov 08 19:17:02 2011 +0100
@@ -4823,17 +4823,30 @@
 
           if (! error_state)
             {
-              octave_value p_arg = (nargin > 1) ? args(1) : octave_value (2);
+              octave_value p_arg;
+              if (nargin > 1 && args(nargin-1).is_string ())
+              {
+                std::string str = args(nargin-1).string_value ();
+                if (str == "fro")
+                  p_arg = octave_value (2);
+                else if (str == "inf")
+                  error ("norm: Inf not yet implemented for cols/rows");
+              }
+              else if (nargin > 1)
+                p_arg = args(1);
+              else
+                p_arg = octave_value (2);
+
               switch (strflag)
                 {
                 case sfmatrix:
                   retval(0) = xnorm (x_arg, p_arg);
                   break;
                 case sfcols:
-                  retval(0) = xcolnorms (x_arg, p_arg);
+                    retval(0) = xcolnorms (x_arg, p_arg);
                   break;
                 case sfrows:
-                  retval(0) = xrownorms (x_arg, p_arg);
+                    retval(0) = xrownorms (x_arg, p_arg);
                   break;
                 case sffrob:
                   retval(0) = xfrobnorm (x_arg);
@@ -4903,6 +4916,16 @@
 %! fhi = single(1e+300);
 %!assert (norm(flo*m2,"fro"), single(sqrt(30)*flo), -eps('single'))
 %!assert (norm(fhi*m2,"fro"), single(sqrt(30)*fhi), -eps('single'))
+
+%!shared q
+%! q = rand(1e3,3);
+%!assert(norm(q,3,"rows") ,sum(q.^3,2).^(1/3),sqrt(eps));
+%!assert(norm(q,"fro","rows") ,sum(q.^2,2).^(1/2),sqrt(eps));
+%!assert(norm(q,"fro","rows") ,sqrt(sumsq(q,2)),sqrt(eps));
+%!assert(norm(q,"fro","cols") ,sqrt(sumsq(q,1)),sqrt(eps));
+%!assert(norm(q,3,"cols") ,sum(q.^3,1).^(1/3),sqrt(eps));
+%!error <Inf not yet implemented> norm(q,"inf","rows");
+%!error <Inf not yet implemented> norm(q,"inf","cols");
 */
 
 static octave_value
# HG changeset patch
# User Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
# Date 1320882838 -3600
# Branch stable
# Node ID 7e4214ba23f1525b63eed2fd349a5eb245540bbf
# Parent  708e4224c424b3219c9e5c957bca9e019b9a96aa
Adding is_function_handle to ov-fcn-handle.cc

diff -r 708e4224c424 -r 7e4214ba23f1 src/ov-fcn-handle.cc
--- a/src/ov-fcn-handle.cc	Tue Nov 08 19:17:02 2011 +0100
+++ b/src/ov-fcn-handle.cc	Thu Nov 10 00:53:58 2011 +0100
@@ -1742,6 +1742,38 @@
 %! assert (testrecursionfunc (@(x) x, 1), 8);
 */
 
+
+DEFUN (is_function_handle, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} is_function_handle (@var{x})\n\
+Return true if @var{x} is a function handle.\n\
+@seealso{ischar, isfloat, isinteger, islogical, isnumeric, iscellstr, isa}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin == 1)
+    retval = args(0).is_function_handle ();
+  else
+    print_usage ();
+
+  return retval;
+}
+
+/*
+%!shared fh
+%! fh=@(x)x;
+
+%!assert (is_function_handle (fh), logical (1));
+%!assert (is_function_handle ({fh}), logical (0));
+%!assert (is_function_handle (1), logical (0));
+%!error <Invalid call to is_function_handle.*> is_function_handle ();
+
+ */
+
+
 octave_fcn_binder::octave_fcn_binder (const octave_value& f,
                                       const octave_value& root,
                                       const octave_value_list& templ,
