# HG changeset patch # User Abhinav Tripathi # Date 1470208720 25200 # Node ID f5282c87e5d5e8f72c197db5001ceae27fc2df0d # Parent 9e8faa439d1de9ffa323e9b8d65a0b5b1acdacf4 Fix cell indexing for pyobject in subsref * @pyobject/subsref.m: Allow indexing pyobjects with cell type indexing with ranges and {:} diff -r 9e8faa439d1d -r f5282c87e5d5 @pyobject/subsref.m --- 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