Skip to content

Commit f45116d

Browse files
committed
BF: inf/-inf/nan now work with get_variable
1 parent a4feb32 commit f45116d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

pymatbridge/matlab/util/json_v0.2.2/json/json_dump.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
double_struct = struct;
107107
double_struct.ndarray = 1;
108108
value = double(value);
109-
if isreal(value)
109+
if isreal(value)
110110
double_struct.data = base64encode(typecast(value(:), 'uint8'));
111111
else
112112
double_struct.real = base64encode(typecast(real(value(:)), 'uint8'));
@@ -142,9 +142,13 @@
142142
obj.put(dump_data_(value{i}, options));
143143
end
144144
elseif isnumeric(value)
145-
if isreal(value)
145+
if ~isfinite(value)
146+
json_non_finite = struct;
147+
json_non_finite.json_non_finite = lower(num2str(value));
148+
obj = dump_data_(json_non_finite, options);
149+
elseif isreal(value)
146150
obj = value;
147-
% Encode complex number as a struct
151+
% Encode finite complex number as a struct
148152
else
149153
complex_struct = struct;
150154
complex_struct.real = real(value);
@@ -158,7 +162,7 @@
158162
keys = fieldnames(value);
159163
for i = 1:length(keys)
160164
try
161-
obj.put(keys{i},dump_data_(value.(keys{i}), options));
165+
obj.put(keys{i}, dump_data_(value.(keys{i}), options));
162166
catch ME
163167
obj.put(keys{i}, dump_data_(ME.message, options))
164168
end

pymatbridge/matlab/util/pymat_eval.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function json_response = pymat_eval(req);
1+
function json_response = pymat_eval(req)
22
% PYMAT_EVAL: Returns a json object of the result of calling the function
33
%
44
% json_response = pymat_eval(req);

pymatbridge/pymatbridge.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def decode_pymat(dct):
108108
return data.reshape(shape, order='F')
109109
elif 'real' in dct and 'imag' in dct:
110110
return complex(dct['real'], dct['imag'])
111+
elif 'json_non_finite' in dct:
112+
return float(dct['json_non_finite'])
111113
return dct
112114

113115
MATLAB_FOLDER = '%s/matlab' % os.path.realpath(os.path.dirname(__file__))

0 commit comments

Comments
 (0)