Skip to content

Commit eced56f

Browse files
committed
Merge commit '4e1b07c' into pytave
2 parents 6125368 + 4e1b07c commit eced56f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

inst/private/check_and_convert.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,23 @@
2929
'if isinstance(temp, sp.Matrix) and temp.shape == (1, 1):',
3030
[' ' cur_var ' = temp[0, 0]']}, newl));
3131

32-
32+
is_dict_with_sym_keys_curvar = pyeval(['isinstance(', cur_var, ', dict) and len(' cur_var '.keys())>0 and isinstance(' cur_var, '.keys()[0], (sp.Basic, sp.MatrixBase))']);
3333
is_list_curvar = pyeval(['isinstance(', cur_var, ', (list, tuple))']);
34+
3435
if is_list_curvar
3536
obj{i} = check_and_convert(cur_var);
37+
elseif is_dict_with_sym_keys_curvar
38+
%if cur_var is dictionary with symbols as keys then convert it to a struct
39+
pyexec(strjoin({'_allKeysStr = []',
40+
'_allValues = []',
41+
['for key, value in ' cur_var '.iteritems():'],
42+
' _allKeysStr.append(str(key))',
43+
' _allValues.append(value)'}, newl));
44+
_allKeysStr = pyeval('_allKeysStr');
45+
obj{i} = struct ();
46+
for j = 1:numel(_allKeysStr)
47+
obj{i}.(_allKeysStr{j}) = get_sym_from_python(sprintf('_allValues[%d]', j-1));
48+
end
3649
else
3750
pyexec(strjoin({ ...
3851
['if ' cur_var ' is None or isinstance(' cur_var ', (sp.Basic, sp.MatrixBase)):'],

0 commit comments

Comments
 (0)