# HG changeset patch # User Colin Macdonald # Date 1470281613 25200 # Node ID df1bddece9d568af7f512813e8a4c55dbdd24359 # Parent e7ee2c2e64e813ed897cbc5f6887c248a38f1e26 Use subsref in "cell" method for casting to cell Remove custom loop and replace it with call to improved subsref. * @pyobject/cell.m: Use subsref instead of loop. * changed @pyobject/fieldnames.m: Use cell. * changed @pyobject/methods.m: Use cell. diff -r e7ee2c2e64e8 -r df1bddece9d5 @pyobject/cell.m --- a/@pyobject/cell.m Wed Aug 03 20:22:42 2016 -0700 +++ b/@pyobject/cell.m Wed Aug 03 20:33:33 2016 -0700 @@ -67,15 +67,13 @@ ## @end defmethod -function c = cell (L) - ## XXX: better implementation available possible in C++? - - c = {}; - #c = cell (size (L)); # scary, b/c "size" calls "cell" - - for i = 1:length (L) # not numel - c{i} = subsref (L, struct ("type", "{}", "subs", {{i}})); - endfor +function c = cell (x) + ## FIXME: subsref should take care of this case + if (length (x) == 0) + c = cell (0, 1); + return + endif + c = subsref (x, struct ("type", "{}", "subs", {{":"}})); endfunction diff -r e7ee2c2e64e8 -r df1bddece9d5 @pyobject/fieldnames.m --- a/@pyobject/fieldnames.m Wed Aug 03 20:22:42 2016 -0700 +++ b/@pyobject/fieldnames.m Wed Aug 03 20:33:33 2016 -0700 @@ -53,14 +53,7 @@ " and not a.startswith('_')]"]); names_obj = pycall (cmd, x); - ## FIXME: names = cellfun (@char, cell (names_obj), "uniformoutput", false); - len = length (names_obj); - names = cell (len, 1); - if (len > 0) - idx = struct ("type", "{}", "subs", {{1:len}}); - [names{1:len}] = subsref (names_obj, idx); - names = cellfun (@char, names, "uniformoutput", false); - endif + names = cellfun (@char, cell (names_obj), "uniformoutput", false); endfunction diff -r e7ee2c2e64e8 -r df1bddece9d5 @pyobject/methods.m --- a/@pyobject/methods.m Wed Aug 03 20:22:42 2016 -0700 +++ b/@pyobject/methods.m Wed Aug 03 20:33:33 2016 -0700 @@ -73,14 +73,7 @@ mtds_list_obj = pycall (cmd, x); - ## FIXME: mtds_list = cellfun (@char, cell (mtds_list_obj), "uniformoutput", false); - len = length (mtds_list_obj); - mtds_list = cell (len, 1); - if (len > 0) - idx = struct ("type", "{}", "subs", {{1:len}}); - [mtds_list{1:len}] = subsref (mtds_list_obj, idx); - mtds_list = cellfun (@char, mtds_list, "uniformoutput", false); - endif + mtds_list = cellfun (@char, cell (mtds_list_obj), "uniformoutput", false); if (nargout == 0) ## FIXME: should this be available as @pyobject/ismodule.m ?