changeset 27097:bdd2964964cc

maint: Merge stable to default.
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Mon, 20 May 2019 09:46:30 +0200
parents f16471efcdf4 (current diff) deb0273199a2 (diff)
children 5fa8d1459b35
files doc/interpreter/genpropdoc.m test/classes/classes.tst
diffstat 19 files changed, 113 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/genpropdoc.m	Thu May 16 23:08:54 2019 +0200
+++ b/doc/interpreter/genpropdoc.m	Mon May 20 09:46:30 2019 +0200
@@ -1115,10 +1115,10 @@
         s.valid = "scalar";
 
       case "position"
-        s.doc = "Vector @code{[X0 Y0 Z0]} where X0, Y0 and Z0 indicate the \
+        s.doc = "Vector @code{[X0 Y0 Z0]} where X0, Y0, and Z0 indicate the \
 position of the text anchor as defined by @code{verticalalignment} and \
 @code{horizontalalignment}.";
-        s.valid = valid_4elvec;
+        s.valid = valid_3elvec;
 
       case "rotation"
         s.doc = "The angle of rotation for the displayed text, \
--- a/libinterp/operators/op-class.cc	Thu May 16 23:08:54 2019 +0200
+++ b/libinterp/operators/op-class.cc	Mon May 20 09:46:30 2019 +0200
@@ -71,8 +71,59 @@
 DEF_CLASS_UNOP (not)
 DEF_CLASS_UNOP (uplus)
 DEF_CLASS_UNOP (uminus)
-DEF_CLASS_UNOP (transpose)
-DEF_CLASS_UNOP (ctranspose)
+
+// In case of (conjugate) transpose first check for overloaded class method.
+// If not overloaded, just transpose the underlying map_value, if the number
+// of dimensions is maximal two.  Matlab compatibility.
+
+// FIXME: Default transposition for classdef arrays.
+
+#define DEF_CLASS_UNOP_TRANS(name)                                       \
+  static octave_value                                                    \
+  oct_unop_ ## name (const octave_value& a)                              \
+  {                                                                      \
+    octave_value retval;                                                 \
+                                                                         \
+    std::string class_name = a.class_name ();                            \
+                                                                         \
+    octave::symbol_table& symtab                                         \
+      = octave::__get_symbol_table__ ("oct_unop_" #name);                \
+                                                                         \
+    octave_value meth = symtab.find_method (#name, class_name);          \
+                                                                         \
+    if (meth.is_undefined ())                                            \
+      {                                                                  \
+        if (a.ndims () > 2)                                              \
+          error ("#name not defined for N-D objects");                   \
+                                                                         \
+        if (! a.is_classdef_object ())                                   \
+          {                                                              \
+            const octave_class& v                                        \
+              = dynamic_cast<const octave_class&> (a.get_rep ());        \
+                                                                         \
+            return octave_value (v.map_value ().transpose (),            \
+                                 v.class_name (),                        \
+                                 v.parent_class_name_list ());           \
+          }                                                              \
+        else                                                             \
+          error ("%s method not defined for %s class", #name,            \
+             class_name.c_str ());                                       \
+      }                                                                  \
+                                                                         \
+    octave_value_list args;                                              \
+                                                                         \
+    args(0) = a;                                                         \
+                                                                         \
+    octave_value_list tmp = octave::feval (meth.function_value (), args, 1); \
+                                                                         \
+    if (tmp.length () > 0)                                               \
+      retval = tmp(0);                                                   \
+                                                                         \
+    return retval;                                                       \
+  }
+
+DEF_CLASS_UNOP_TRANS (transpose)
+DEF_CLASS_UNOP_TRANS (ctranspose)
 
 // The precedence of the oct_binop_*-functions is as follows:
 //
--- a/scripts/special-matrix/gallery.m	Thu May 16 23:08:54 2019 +0200
+++ b/scripts/special-matrix/gallery.m	Mon May 20 09:46:30 2019 +0200
@@ -286,7 +286,7 @@
 ##
 ## @end deftypefn
 ##
-## @deftypefn {} {@var{a} =} gallery ("Poisson", @var{n})
+## @deftypefn {} {@var{a} =} gallery ("poisson", @var{n})
 ## Create a block tridiagonal matrix from Poisson's equation (sparse).
 ##
 ## @end deftypefn
--- a/test/classes/@Gork/subsasgn.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@Gork/subsasgn.m	Mon May 20 09:46:30 2019 +0200
@@ -5,6 +5,7 @@
     switch s.subs
     case 'gyrk'
       g.gyrk = x;
+    end
   end
 
 end
--- a/test/classes/@Gork/subsref.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@Gork/subsref.m	Mon May 20 09:46:30 2019 +0200
@@ -5,6 +5,7 @@
     switch s.subs
     case 'gyrk'
       x = g.gyrk;
+    end
   end
 
 end
--- a/test/classes/@SizeTester/SizeTester.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@SizeTester/SizeTester.m	Mon May 20 09:46:30 2019 +0200
@@ -3,4 +3,4 @@
   x = struct ("desired_size", desired_size);
   x = class (x, "SizeTester");
 
-endfunction
+end
--- a/test/classes/@SizeTester/numel.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@SizeTester/numel.m	Mon May 20 09:46:30 2019 +0200
@@ -2,4 +2,4 @@
 
   n = prod (this.desired_size);
 
-endfunction
+end
--- a/test/classes/@SizeTester/size.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@SizeTester/size.m	Mon May 20 09:46:30 2019 +0200
@@ -2,4 +2,4 @@
 
   s = this.desired_size;
 
-endfunction
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/classes/@Snork/ctranspose.m	Mon May 20 09:46:30 2019 +0200
@@ -0,0 +1,7 @@
+function s = ctranspose (s)
+
+  x = double (s);
+
+  s = Snork (x' + 4);  % +4 To make sure some non-standard tranpose is called.
+
+end
--- a/test/classes/@Snork/end.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@Snork/end.m	Mon May 20 09:46:30 2019 +0200
@@ -1,6 +1,6 @@
 function r = end (snk, index_pos, num_indices)
 
-  if (num_indices != 1)
+  if (num_indices ~= 1)
     error ('Snork object may only have one index')
   end
 
--- a/test/classes/@Snork/mpower.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@Snork/mpower.m	Mon May 20 09:46:30 2019 +0200
@@ -1,6 +1,6 @@
 function s = mpower (s1, x)
 
-  if (!isa (s1, 'Snork') || isa (x, 'Snork'))
+  if (~isa (s1, 'Snork') || isa (x, 'Snork'))
     error ('mpower Snork!!!');
   end
 
--- a/test/classes/@Snork/ne.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@Snork/ne.m	Mon May 20 09:46:30 2019 +0200
@@ -1,5 +1,5 @@
 function b = ne (s1, s2)
 
-  b = !(s1 == s2);
+  b = ~(s1 == s2);
 
 end
--- a/test/classes/@Snork/power.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@Snork/power.m	Mon May 20 09:46:30 2019 +0200
@@ -1,6 +1,6 @@
 function s = power (s1, x)
 
-  if (!isa (s1, 'Snork') || isa (x, 'Snork'))
+  if (~isa (s1, 'Snork') || isa (x, 'Snork'))
     error ('power Snork!!!');
   end
 
--- a/test/classes/@Snork/subsasgn.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@Snork/subsasgn.m	Mon May 20 09:46:30 2019 +0200
@@ -6,7 +6,7 @@
   switch (s(1).type)
     case '()'
       ind = s(1).subs;
-      if (numel (ind) != 1)
+      if (numel (ind) ~= 1)
         error ('Snork: need exactly one index');
       else
         if (length (s) == 1)
@@ -17,7 +17,7 @@
       end
     case '{}'
       ind = s(1).subs;
-      if (numel (ind) != 1)
+      if (numel (ind) ~= 1)
         error ('Snork: need exactly one index');
       else
         if (length (s) == 1)
--- a/test/classes/@Snork/subsref.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@Snork/subsref.m	Mon May 20 09:46:30 2019 +0200
@@ -6,14 +6,14 @@
   switch (s(1).type)
     case '()'
       ind = s(1).subs;
-      if (numel (ind) != 1)
+      if (numel (ind) ~= 1)
         error ('Snork: need exactly one index');
       else
         b = snk.cack(ind{1});
       end
     case '{}'
       ind = s(1).subs;
-      if (numel (ind) != 1)
+      if (numel (ind) ~= 1)
         error ('Snork: need exactly one index');
       else
         b = snk.cack(ind{1});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/classes/@Snork/transpose.m	Mon May 20 09:46:30 2019 +0200
@@ -0,0 +1,7 @@
+function s = transpose (s)
+
+  x = double (s);
+
+  s = Snork (x.' + 2);  % +2 To make sure some non-standard tranpose is called.
+
+end
--- a/test/classes/@Spork/loadobj.m	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/@Spork/loadobj.m	Mon May 20 09:46:30 2019 +0200
@@ -1,7 +1,7 @@
 function out = loadobj (in)
 
   out = in;
-  if (!isa (in, 'Spork'))
+  if (~isa (in, 'Spork'))
     out.cack = [];
   end
 
--- a/test/classes/classes.tst	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/classes.tst	Mon May 20 09:46:30 2019 +0200
@@ -272,17 +272,17 @@
 %!assert (s1 == s1)
 %!assert (s1 == x1)
 %!assert (x1 == s1)
-%!assert (!(s1 == (s1 + 1)))
-%!assert (!(s1 == (x1 + 1)))
-%!assert (!(x1 == (s1 + 1)))
+%!assert (~(s1 == (s1 + 1)))
+%!assert (~(s1 == (x1 + 1)))
+%!assert (~(x1 == (s1 + 1)))
 
-%% Test overloaded ne (!=) for the Snork class
-%!assert (!(s1 != s1))
-%!assert (!(s1 != x1))
-%!assert (!(x1 != s1))
-%!assert (s1 != (s1 + 1))
-%!assert (x1 != (s1 + 1))
-%!assert (s1 != (x1 + 1))
+%% Test overloaded ne (~=) for the Snork class
+%!assert (~(s1 ~= s1))
+%!assert (~(s1 ~= x1))
+%!assert (~(x1 ~= s1))
+%!assert (s1 ~= (s1 + 1))
+%!assert (x1 ~= (s1 + 1))
+%!assert (s1 ~= (x1 + 1))
 
 %% Test overloaded lt (<) for the Snork class
 %!assert (s1 < (s1 + 1))
@@ -304,9 +304,13 @@
 %!assert (s1 >= (x1 - 1))
 %!assert (x1 >= (s1 - 1))
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% Testing horizontal & vertical concatenation %%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Testing concatenation and transposition %%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%% Test overloaded (c)transpose for the Snork class
+%!assert (isequal (s1',  Snork (double (s1)'  + 4)))  % +4 is intentional
+%!assert (isequal (s1.', Snork (double (s1).' + 2)))  % +2 is intentional
 
 %% Test overloaded vertcat() for the Snork class
 %!test <*38128>
@@ -324,8 +328,8 @@
 %!test <*38128>
 %! s = [x1 s2];  assert (isa (s, 'Snork') && isequal (s.gick, [x1 x2]));
 
-%% Test with the Blork class, where neither vertcat() nor horzcat()
-%% is overloaded
+%% Test with the Blork class, where neither ctranspose(), transpose(),
+%% vertcat() nor horzcat() is overloaded
 %!shared x1, x2, x3
 %!test x1 = Blork ();
 %!test x2 = [x1 x1];
@@ -338,6 +342,9 @@
 %!assert (isa (x3, 'Blork') && isequal (size (x3), [2 2]))
 %!error <dimension mismatch> x4 = [x1, x3]
 %!error <dimension mismatch> x4 = [x1; x3]
+%!test x2 = [x1 x1];
+%!assert (isequal (x2',  [x1; x1]) && isequal (size (x2'),  [2 1]))
+%!assert (isequal (x2.', [x1; x1]) && isequal (size (x2.'), [2 1]))
 
 %%%%%%%%%%%%%%%%%%%%%%%%
 %% Testing precedence %%
@@ -372,11 +379,11 @@
 %% Trying to change to CPrecendenceTester3 > Snork
 %!error D = CPrecedenceTester3 (1)
 
-##############################################
-## Testing overridden size+numel method     ##
-## (builtin size method and similar methods ##
-## use the size of the struct container)    ##
-##############################################
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Testing overridden size+numel method     %%
+%% (builtin size method and similar methods %%
+%% use the size of the struct container)    %%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 %!shared st
 %!test st = SizeTester ([1 1]);
--- a/test/classes/module.mk	Thu May 16 23:08:54 2019 +0200
+++ b/test/classes/module.mk	Mon May 20 09:46:30 2019 +0200
@@ -48,6 +48,7 @@
 class_Snork_TEST_FILES = \
   %reldir%/@Snork/Snork.m \
   %reldir%/@Snork/cack.m \
+  %reldir%/@Snork/ctranspose.m \
   %reldir%/@Snork/display.m \
   %reldir%/@Snork/double.m \
   %reldir%/@Snork/end.m \
@@ -79,6 +80,7 @@
   %reldir%/@Snork/subsref.m \
   %reldir%/@Snork/tattack.m \
   %reldir%/@Snork/times.m \
+  %reldir%/@Snork/transpose.m \
   %reldir%/@Snork/uminus.m \
   %reldir%/@Snork/uplus.m \
   %reldir%/@Snork/vertcat.m