@@ -66,6 +66,17 @@ def zip_if_several(*params) -> tuple | list[tuple]:
6666 return zip (* params , strict = False )
6767 return [params ]
6868
69+ def __opaque_to_string (opaque ):
70+ entries = opaque [0 ]
71+ for entry in entries :
72+ if isinstance (entry , ndarray ):
73+ break
74+ else :
75+ raise ValueError ("No array in MatlabOpaque" )
76+
77+ return bytes (entry [7 :]).decode ("ascii" )
78+
79+
6980 def read_param (names , constrs , values , fits ):
7081 """Read in a parameter list from the relevant keys, and fix constraints for non-fit parameters.
7182
@@ -217,11 +228,11 @@ def fix_invalid_constraints(name: str, constrs: tuple[float, float], value: floa
217228 # which is given as the byte data of a Java string; this consists of 7 metadata bytes (ignored)
218229 # and then the actual string characters (index [7:]) in ascii format (.decode("ascii"))
219230 if len (mat_project ["contrastNames" ]) == 1 and isinstance (mat_project ["contrastNames" ], MatlabOpaque ):
220- mat_project ["contrastNames" ] = bytes (mat_project ["contrastNames" ][ 0 ][ 3 ][ 7 :]). decode ( "ascii" )
231+ mat_project ["contrastNames" ] = __opaque_to_string (mat_project ["contrastNames" ])
221232 else :
222233 for i , contrast_name in enumerate (mat_project ["contrastNames" ]):
223234 if isinstance (contrast_name , MatlabOpaque ):
224- mat_project ["contrastNames" ][i ] = bytes (contrast_name [ 0 ][ 3 ][ 7 :]). decode ( "ascii" )
235+ mat_project ["contrastNames" ][i ] = __opaque_to_string (contrast_name )
225236
226237 # if just one contrast, resolNames is a string; fix that here
227238 if isinstance (mat_project ["resolNames" ], str ):
0 commit comments