Skip to content

Commit 151ebac

Browse files
committed
[bug] fix parsing mixed-type scalars arrays in bjdata
1 parent e5fb547 commit 151ebac

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

loadbj.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,12 @@
441441
if (iscell(object) && length(object) > 1 && ndims(object{1}) >= 2)
442442
catdim = size(object{1});
443443
catdim = ndims(object{1}) - (catdim(end) == 1) + 1;
444-
object = cat(catdim, object{:});
444+
if (~all(cellfun(@(e) isa(e, class(object{1})), object(2:end))))
445+
tmp = cellfun(@double, object, 'UniformOutput', false);
446+
object = cat(catdim, tmp{:});
447+
else
448+
object = cat(catdim, object{:});
449+
end
445450
object = permute(object, ndims(object):-1:1);
446451
else
447452
object = cell2mat(object')';

test/run_jsonlab_test.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4749,7 +4749,7 @@ function run_jsonlab_test(tests)
47494749
clear sp2d_nd enc_spnd dec_spnd enc_spnd_json dec_spnd_json;
47504750

47514751
%% --- _ArrayChunks_ with sparse complex arrays (1-D) ---
4752-
spcpx = sparse([1 3], [2 4], [1+2i 3+4i], 4, 5); % 2 complex nonzeros
4752+
spcpx = sparse([1 3], [2 4], [1 + 2i 3 + 4i], 4, 5); % 2 complex nonzeros
47534753
enc_spcpx1d = jdataencode(spcpx, 'formatversion', 4, 'compression', 'zlib', ...
47544754
'arraychunks', 2, 'base64', 1, 'prefix', 'x', 'compressarraysize', 1);
47554755
test_jsonlab('complex sparse 1d chunks IsSparse+IsComplex', @savejson, ...

0 commit comments

Comments
 (0)