Skip to content

Commit

Permalink
fix(fjagepy): add support for list of complex numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
notthetup committed Jul 24, 2024
1 parent 66d13ff commit b7d5b8a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gateways/python/fjagepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,17 @@ def _serialize(self):
t = [key for key, value in self.__dict__.items() if key.startswith('__')]
for i in t:
m.pop(i)
for key, value in m.items():
for key, value in list(m.items()):
if type(value) == numpy.ndarray:
if value.dtype == 'complex':
value = numpy.vstack((value.real, value.imag)).reshape((-1,), order='F')
m[key + '__isComplex'] = True
m[key] = value.tolist()
elif type(value) == list and len(value) > 0:
if (type(value[0]) == complex):
value = numpy.vstack((numpy.real(value), numpy.imag(value))).reshape((-1,), order='F')
m[key + '__isComplex'] = True
m[key] = value.tolist()
data = _json.dumps(m, separators=(',', ':'), cls=_CustomEncoder)
return '{ "clazz": "' + clazz + '", "data": ' + data + ' }'

Expand Down

0 comments on commit b7d5b8a

Please sign in to comment.