1
+ from functools import partial
2
+ import numpy as np
1
3
from ..utils import (
2
4
_matlab_array_types ,
3
5
_import_matlab ,
4
- )
5
- from functools import partial
6
- import numpy as np
6
+ )
7
+
7
8
8
9
class MatlabType (object ):
9
10
"""Generic type for objects that have an exact matlab equivalent."""
@@ -16,10 +17,10 @@ def from_any(cls, other, **kwargs):
16
17
17
18
!!! warning "Conversion is performed in-place when possible."
18
19
"""
19
- # FIXME: Circular import
20
+ # FIXME: Circular import
20
21
from .delayed_types import AnyDelayedArray
21
22
22
- # FIXME: Circular import
23
+ # FIXME: Circular import
23
24
from ..cell import Cell
24
25
from ..array import Array
25
26
from ..matlab_function import MatlabFunction
@@ -45,11 +46,20 @@ def from_any(cls, other, **kwargs):
45
46
if "type__" in other :
46
47
type__ = other ["type__" ]
47
48
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" :
49
55
# MPython returns a list of dictionaries in data__
50
56
# and the array shape in size__.
51
57
return Struct ._from_runtime (other )
52
58
59
+ elif type__ == "emptystruct" :
60
+ # 0x0 struct
61
+ return Struct .from_shape ([0 ])
62
+
53
63
elif type__ == "cell" :
54
64
# MPython returns a list of dictionaries in data__
55
65
# and the array shape in size__.
@@ -81,8 +91,7 @@ def from_any(cls, other, **kwargs):
81
91
82
92
else :
83
93
other = type (other )(
84
- zip (other .keys (),
85
- map (_from_any , other .values ()))
94
+ zip (other .keys (), map (_from_any , other .values ()))
86
95
)
87
96
return Struct .from_any (other )
88
97
@@ -135,7 +144,7 @@ def _to_runtime(cls, obj):
135
144
Convert object to representation that the matlab runtime understands.
136
145
"""
137
146
to_runtime = cls ._to_runtime
138
- from ..utils import sparse # FIXME: Circular import
147
+ from ..utils import sparse # FIXME: Circular import
139
148
140
149
if isinstance (obj , MatlabType ):
141
150
# class / structarray / cell
@@ -159,7 +168,7 @@ def _to_runtime(cls, obj):
159
168
return obj
160
169
161
170
elif sparse and isinstance (obj , sparse .sparray ):
162
- from .SparseArray import SparseArray
171
+ from .. sparse_array import SparseArray
163
172
return SparseArray .from_any (obj )._as_runtime ()
164
173
165
174
else :
@@ -182,6 +191,7 @@ def _as_matlab_object(self):
182
191
# FIXME: Or just keep `_as_matlab_object` and remove `_as_runtime`?
183
192
return self ._as_runtime ()
184
193
194
+
185
195
class AnyMatlabArray (MatlabType ):
186
196
"""Base class for all matlab-like arrays (numeric, cell, struct)."""
187
197
@@ -203,4 +213,4 @@ def as_struct(self):
203
213
f"Cannot interpret a { type (self ).__name__ } as a struct"
204
214
)
205
215
206
- # TODO: `as_obj` for object arrays?
216
+ # TODO: `as_obj` for object arrays?
0 commit comments