Mercurial > octave
changeset 28801:ffa6c50c2eaa
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.
author | Abdallah-Elshamy <abdallah.k.elshamy@gmail.com> |
---|---|
date | Sat, 26 Sep 2020 14:19:23 +0200 |
parents | d28016d16e9a |
children | 191538bdae3f |
files | libinterp/corefcn/jsondecode.cc test/json/jsondecode_BIST.tst |
diffstat | 2 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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]);