# HG changeset patch
# User Julien Bect <julien.bect@centralesupelec.fr>
# Date 1455110962 -3600
#      Wed Feb 10 14:29:22 2016 +0100
# Branch stable
# Node ID 8ee5c2d446fea824dc75e3bfb1431440b460f973
# Parent  b48d65c5df5be06fc50c038739cf7cca9c6cbf18
Respect user-defined size() (bug #43925, bug #44498)

* data.cc (Frows): Call size() insteas of rows().
* data.cc (Fcolumns): Call size() insteas of columns().
* data.cc (Fisscalar): Call size() instead of numel().
* data.cc (Fisrow): Call size() instead of dims().
* data.cc (Fiscolumn): Call size() instead of dims().
* data.cc (Fisvector): Call size() instead of dims().
* data.cc (Fismatrix): Call size() instead of dims().
* data.cc (Fissquare): Call size() instead of dims().

diff -r b48d65c5df5b -r 8ee5c2d446fe libinterp/corefcn/data.cc
--- a/libinterp/corefcn/data.cc	Tue Feb 09 11:54:02 2016 -0800
+++ b/libinterp/corefcn/data.cc	Wed Feb 10 14:29:22 2016 +0100
@@ -2935,7 +2935,11 @@
   octave_value retval;
 
   if (args.length () == 1)
-    retval = args(0).rows ();
+    {
+      // Use size() instead of rows() to allow user overloading.
+      // Create of copy of args(0) since size() isn't const
+      retval = (octave_value (args(0)).size ())(0);
+    }
   else
     print_usage ();
 
@@ -2952,7 +2956,11 @@
   octave_value retval;
 
   if (args.length () == 1)
-    retval = args(0).columns ();
+    {
+      // Use size() instead of columns() to allow user overloading.
+      // Create of copy of args(0) since size() isn't const
+      retval = (octave_value (args(0)).size ())(1);
+    }
   else
     print_usage ();
 
@@ -3717,7 +3725,14 @@
   octave_value retval;
 
   if (args.length () == 1)
-    retval = args(0).numel () == 1;
+    {
+      // Use size() instead of dims() to allow user overloading. *Not*
+      // to be replaced by numel(), since numel() might be overloaded in
+      // such a way that numel(x) differs from prod(size(x)).
+      // Create of copy of args(0) since size() isn't const
+      Matrix sz = octave_value (args(0)).size ();
+      retval = (sz.numel () == 2) && (sz(0) == 1) && (sz(1) == 1);
+    }
   else
     print_usage ();
 
@@ -3757,8 +3772,14 @@
 
   if (args.length () == 1)
     {
-      dim_vector sz = args(0).dims ();
-      retval = sz.length () == 2 && (sz(0) == 1 || sz(1) == 1);
+      // Use size() instead of dims() to allow user overloading.
+      // Create of copy of args(0) since size() isn't const
+      Matrix sz = octave_value (args(0)).size ();
+      // sz must be of the form [1 n] or [n 1],
+      // with n a non-negative integer
+      retval = (sz.numel () == 2)
+        && ((sz(0) == 1 && sz(1) >= 0 && xisinteger (sz(1)))       // row
+            || (sz(1) == 1 && sz(0) >= 0 && xisinteger (sz(0))));  // or column
     }
   else
     print_usage ();
@@ -3797,8 +3818,13 @@
 
   if (args.length () == 1)
     {
-      dim_vector sz = args(0).dims ();
-      retval = sz.length () == 2 && sz(0) == 1;
+      // Use size() instead of dims() to allow user overloading.
+      // Create of copy of args(0) since size() isn't const
+      Matrix sz = octave_value (args(0)).size ();
+      // sz must be of the form [1 n],
+      // with n a non-negative integer
+      retval = (sz.numel () == 2) && (sz(0) == 1)
+        && (sz(1) >= 0) && (xisinteger (sz(1)));
     }
   else
     print_usage ();
@@ -3847,8 +3873,13 @@
 
   if (args.length () == 1)
     {
-      dim_vector sz = args(0).dims ();
-      retval = sz.length () == 2 && sz(1) == 1;
+      // Use size() instead of dims() to allow user overloading.
+      // Create of copy of args(0) since size() isn't const
+      Matrix sz = octave_value (args(0)).size ();
+      // sz must be of the form [n 1],
+      // with n a non-negative integer
+      retval = (sz.numel () == 2) && (sz(1) == 1)
+        && (sz(0) >= 0) && (xisinteger (sz(0)));
     }
   else
     print_usage ();
@@ -3896,8 +3927,14 @@
 
   if (args.length () == 1)
     {
-      dim_vector sz = args(0).dims ();
-      retval = (sz.length () == 2) && (sz(0) >= 0) && (sz(1) >= 0);
+      // Use size() instead of dims() to allow user overloading.
+      // Create of copy of args(0) since size() isn't const
+      Matrix sz = octave_value (args(0)).size ();
+      // sz must be of the form [m n],
+      // with m and n non-negative integers
+      retval = (sz.numel () == 2)
+        && (sz(0) >= 0) && (xisinteger (sz(0)))
+        && (sz(1) >= 0) && (xisinteger (sz(1)));
     }
   else
     print_usage ();
@@ -3944,8 +3981,13 @@
 
   if (args.length () == 1)
     {
-      dim_vector sz = args(0).dims ();
-      retval = sz.length () == 2 && sz(0) == sz(1);
+      // Use size() instead of dims() to allow user overloading.
+      // Create of copy of args(0) since size() isn't const
+      Matrix sz = octave_value (args(0)).size ();
+      // sz must be of the form [n n],
+      // with n a non-negative integer
+      retval = (sz.numel () == 2) && (sz(0) == sz(1))
+        && (sz(0) >= 0) && (xisinteger (sz(0)));
     }
   else
     print_usage ();
diff -r b48d65c5df5b -r 8ee5c2d446fe test/classes/classes.tst
--- a/test/classes/classes.tst	Tue Feb 09 11:54:02 2016 -0800
+++ b/test/classes/classes.tst	Wed Feb 10 14:29:22 2016 +0100
@@ -1,4 +1,4 @@
-## Copyright (C) 2013-2015 Julien Bect
+## Copyright (C) 2013-2016 Julien Bect
 ## Copyright (C) 2009-2015 Robert T. Short
 ##
 ## This file is part of Octave.
@@ -310,15 +310,15 @@
 
 %% Test overloaded vertcat() for the Snork class
 %% See bug #38128 (http://savannah.gnu.org/bugs/?38128)
-%!test   s = [s1; s2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1; x2]));
-%!xtest  s = [s1; x2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1; x2]));
-%!xtest  s = [x1; s2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1; x2]));
+%!test  s = [s1; s2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1; x2]));
+%!test  s = [s1; x2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1; x2]));
+%!test  s = [x1; s2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1; x2]));
 
 %% Test overloaded horzcat() for the Snork class
 %% See bug #38128 (http://savannah.gnu.org/bugs/?38128)
-%!test   s = [s1 s2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1 x2]));
-%!xtest  s = [s1 x2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1 x2]));
-%!xtest  s = [x1 s2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1 x2]));
+%!test  s = [s1 s2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1 x2]));
+%!test  s = [s1 x2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1 x2]));
+%!test  s = [x1 s2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1 x2]));
 
 %% Test with the Blork class, where neither vertcat() nor horzcat() is overloaded
 %!shared x1, x2, x3
@@ -367,6 +367,10 @@
 ## use the size of the struct container)    ##
 ##############################################
 
+% See related bug reports
+%  * bug #43925  (http://savannah.gnu.org/bugs/?43925)
+%  * bug #44498  (http://savannah.gnu.org/bugs/?44498)
+
 %!shared st
 %!test st = SizeTester ([1 1]);
 %! assert (isequal (size (st), [1 1]))
@@ -383,27 +387,27 @@
 %! assert (isequal (numel (st), 2))
 %!assert (isequal (ndims (st), 2))
 %!assert (isequal (rows (st), 1))
-%!xtest assert (isequal (columns (st), 2))
-%!assert (isequal (st, st))                # bug #44334
-%!xtest assert (not (isscalar (st)))       # bug #44498
+%!test assert (isequal (columns (st), 2))
+%!assert (isequal (st, st))
+%!test assert (not (isscalar (st)))
 %!assert (isvector (st))
 
 %!test st = SizeTester ([2 3]);
 %! assert (isequal (size (st), [2 3]))
 %! assert (isequal (numel (st), 6))
 %!assert (isequal (ndims (st), 2))
-%!xtest assert (isequal (rows (st), 2))
-%!xtest assert (isequal (columns (st), 3))
-%!assert (isequal (st, st))                # bug #44334
-%!xtest assert (not (isscalar (st)))       # bug #44498
-%!xtest assert (not (isvector (st)))       # bug #44498
+%!test assert (isequal (rows (st), 2))
+%!test assert (isequal (columns (st), 3))
+%!assert (isequal (st, st))
+%!test assert (not (isscalar (st)))
+%!test assert (not (isvector (st)))
 
 %!test st = SizeTester ([2 3 4]);
 %! assert (isequal (size (st), [2 3 4]))
 %! assert (isequal (numel (st), 24))
-%!xtest assert (isequal (ndims (st), 3))
-%!xtest assert (isequal (rows (st), 2))
-%!xtest assert (isequal (columns (st), 3))
-%!assert (isequal (st, st))                # bug #44334
-%!xtest assert (not (isscalar (st)))       # bug #44498
-%!xtest assert (not (isvector (st)))       # bug #44498
+%!test assert (isequal (ndims (st), 3))
+%!test assert (isequal (rows (st), 2))
+%!test assert (isequal (columns (st), 3))
+%!assert (isequal (st, st))
+%!test assert (not (isscalar (st)))
+%!test assert (not (isvector (st)))
