changeset 288:f5282c87e5d5

Fix cell indexing for pyobject in subsref * @pyobject/subsref.m: Allow indexing pyobjects with cell type indexing with ranges and {:}
author Abhinav Tripathi <genuinelucifer@gmail.com>
date Wed, 03 Aug 2016 00:18:40 -0700
parents 9e8faa439d1d
children 49832ca978fd
files @pyobject/subsref.m
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/@pyobject/subsref.m	Tue Aug 02 12:11:02 2016 -0700
+++ b/@pyobject/subsref.m	Wed Aug 03 00:18:40 2016 -0700
@@ -57,7 +57,14 @@
         endif
       endfor
 
-      if (isscalar (t.subs))
+      if (ischar (t.subs{1}) && strcmp (t.subs{1}, ":"))
+        is_map = pyeval ("lambda x: isinstance(x, collections.Mapping)");
+        if (pycall (is_map, x))
+          ind = ":";
+        else
+          ind = int32 ([1:length(x)] - 1);
+        endif
+      elseif (isscalar (t.subs))
         ind = t.subs{1};
       else
         ## XXX: after #26, #27, I think its just:
@@ -70,8 +77,16 @@
         pyexec ("_temp = tuple(_temp[0])");
         ind = pyobject.fromPythonVarName ("_temp");
       endif
+
       gi = pycall ("getattr", x, "__getitem__");   # x.__getitem__
-      r = pycall (gi, ind);
+      if (isnumeric (ind) && length (ind) > 1)
+        r = {};
+        for k = 1:length (ind)
+          r(end+1) = pycall (gi, ind(k));
+        endfor
+      else
+        r = pycall (gi, ind);
+      endif
 
     otherwise
       t
@@ -92,7 +107,7 @@
   elseif (nargout >= 2)
     assert (length (r) == nargout, ...
             "pyobject/subsref: number of outputs must match")
-    [varargout{1:nargout}] = r{1:nargout};
+    [varargout{1:nargout}] = subsref (r, struct ("type", "{}", "subs", {{1:nargout}}));
   endif
 endfunction