@@ -86,14 +86,28 @@ def _from_runtime(cls, dictobj: dict):
86
86
raise ValueError ("Not a matlab sparse matrix" )
87
87
size = np .array (dictobj ["size__" ], dtype = np .uint64 ).ravel ()
88
88
size = size .tolist ()
89
+ ndim = len (size )
89
90
if isinstance (dictobj ["values__" ], float ):
90
91
dtype = np .double
91
92
else :
92
93
dtype = _matlab_array_types ()[type (dictobj ["values__" ])]
93
- indices = np .asarray (dictobj ["indices__" ], dtype = np .long ) - 1
94
+ indices = np .asarray (dictobj ["indices__" ], dtype = np .long )
95
+ # print('from_matlab', indices.shape)
94
96
values = np .asarray (dictobj ["values__" ], dtype = dtype ).ravel ()
97
+ # indices = indices.reshape([ndim, -1])
98
+ indices -= 1
95
99
if indices .size == 0 :
96
- indices = indices .reshape ([0 , len (size )])
100
+ indices = indices .reshape ([0 , ndim ])
101
+ elif indices .shape [0 ] == 1 :
102
+ # NOTE: I've encountered this issue while runngin the PEB
103
+ # tutorial, but it is difficult to find a minimal example.
104
+ # It seems that for some reason, find() has returned row vectors
105
+ # instead of column vectors, so [ii, jj] generates a long row
106
+ # vector. When this is detected, I properly unfold the data,
107
+ # but this should probably be fixed in mpython_endpoint
108
+ # as well.
109
+ indices = indices .reshape ([ndim , - 1 ]).T
110
+ # print(indices)
97
111
return cls .from_coo (values , indices .T , size )
98
112
99
113
0 commit comments