# HG changeset patch # User Abdallah-Elshamy # Date 1601122763 -7200 # Node ID ffa6c50c2eaaf5f4d91c4bd619a2c6dff98dbc62 # Parent d28016d16e9a50b2db4883453a6b4781927b8563 Decode JSON boolean arrays into logical arrays (bug #59135). * jsondecode.cc (decode_array_of_arrys): Check value of is_bool and return either boolNDArray (logical) or NDArray (numeric). * jsondecode_BIST.tst: Remove FIXME for BIST test for bug #59135. diff -r d28016d16e9a -r ffa6c50c2eaa libinterp/corefcn/jsondecode.cc --- a/libinterp/corefcn/jsondecode.cc Sun Sep 27 19:23:53 2020 -0700 +++ b/libinterp/corefcn/jsondecode.cc Sat Sep 26 14:19:23 2020 +0200 @@ -304,10 +304,10 @@ // Calculate the dims of the output array dim_vector array_dims; - array_dims.resize (sub_array_ndims + 1); - array_dims(0) = cell_numel; - for (auto i = 1; i < sub_array_ndims + 1; i++) - array_dims(i) = sub_array_dims(i-1); + array_dims.resize (sub_array_ndims + 1); + array_dims(0) = cell_numel; + for (auto i = 1; i < sub_array_ndims + 1; i++) + array_dims(i) = sub_array_dims(i-1); NDArray array (array_dims); // Populate the array with specific order to generate MATLAB-identical output @@ -315,7 +315,11 @@ for (octave_idx_type i = 0; i < array.numel () / cell_numel; ++i) for (octave_idx_type k = 0; k < cell_numel; ++k) array(array_index++) = cell(k).array_value ()(i); - return array; + + if (is_bool) + return boolNDArray (array); + else + return array; } //! Decodes any type of JSON arrays. This function only serves as an interface diff -r d28016d16e9a -r ffa6c50c2eaa test/json/jsondecode_BIST.tst --- a/test/json/jsondecode_BIST.tst Sun Sep 27 19:23:53 2020 -0700 +++ b/test/json/jsondecode_BIST.tst Sat Sep 26 14:19:23 2020 +0200 @@ -49,7 +49,6 @@ %! assert (isa (obs, 'logical')); %! assert (isequal (obs, exp)); -%% FIXME: Matlab returns logical array rather than numeric array %!testif HAVE_RAPIDJSON <59135> %! json = '[[true, true], [false, true]]'; %! exp = logical ([1, 1; 0, 1]);