1+ from functools import partial
2+ import numpy as np
13from ..utils import (
24 _matlab_array_types ,
35 _import_matlab ,
4- )
5- from functools import partial
6- import numpy as np
6+ )
7+
78
89class MatlabType (object ):
910 """Generic type for objects that have an exact matlab equivalent."""
@@ -16,10 +17,10 @@ def from_any(cls, other, **kwargs):
1617
1718 !!! warning "Conversion is performed in-place when possible."
1819 """
19- # FIXME: Circular import
20+ # FIXME: Circular import
2021 from .delayed_types import AnyDelayedArray
2122
22- # FIXME: Circular import
23+ # FIXME: Circular import
2324 from ..cell import Cell
2425 from ..array import Array
2526 from ..matlab_function import MatlabFunction
@@ -45,11 +46,20 @@ def from_any(cls, other, **kwargs):
4546 if "type__" in other :
4647 type__ = other ["type__" ]
4748
48- if type__ == "structarray" :
49+ if type__ == "none" :
50+ # MPython returns this when run with nargout=1 but
51+ # should have been nargout=0
52+ return None
53+
54+ elif type__ == "structarray" :
4955 # MPython returns a list of dictionaries in data__
5056 # and the array shape in size__.
5157 return Struct ._from_runtime (other )
5258
59+ elif type__ == "emptystruct" :
60+ # 0x0 struct
61+ return Struct .from_shape ([0 ])
62+
5363 elif type__ == "cell" :
5464 # MPython returns a list of dictionaries in data__
5565 # and the array shape in size__.
@@ -81,8 +91,7 @@ def from_any(cls, other, **kwargs):
8191
8292 else :
8393 other = type (other )(
84- zip (other .keys (),
85- map (_from_any , other .values ()))
94+ zip (other .keys (), map (_from_any , other .values ()))
8695 )
8796 return Struct .from_any (other )
8897
@@ -135,7 +144,7 @@ def _to_runtime(cls, obj):
135144 Convert object to representation that the matlab runtime understands.
136145 """
137146 to_runtime = cls ._to_runtime
138- from ..utils import sparse # FIXME: Circular import
147+ from ..utils import sparse # FIXME: Circular import
139148
140149 if isinstance (obj , MatlabType ):
141150 # class / structarray / cell
@@ -159,7 +168,7 @@ def _to_runtime(cls, obj):
159168 return obj
160169
161170 elif sparse and isinstance (obj , sparse .sparray ):
162- from .SparseArray import SparseArray
171+ from .. sparse_array import SparseArray
163172 return SparseArray .from_any (obj )._as_runtime ()
164173
165174 else :
@@ -182,6 +191,7 @@ def _as_matlab_object(self):
182191 # FIXME: Or just keep `_as_matlab_object` and remove `_as_runtime`?
183192 return self ._as_runtime ()
184193
194+
185195class AnyMatlabArray (MatlabType ):
186196 """Base class for all matlab-like arrays (numeric, cell, struct)."""
187197
@@ -203,4 +213,4 @@ def as_struct(self):
203213 f"Cannot interpret a { type (self ).__name__ } as a struct"
204214 )
205215
206- # TODO: `as_obj` for object arrays?
216+ # TODO: `as_obj` for object arrays?
0 commit comments