From 11e9e6089901faba7763e45d00ede420ef825f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Thu, 17 Dec 2020 15:33:33 +0100 Subject: [PATCH] Compatibility fixes for Octave 6 --- src/@dates/intersect.m | 2 + src/@dates/remove_.m | 2 +- src/@dates/setdiff.m | 2 +- src/@dates/unique_.m | 2 +- src/initialize_dseries_class.m | 4 ++ src/utilities/convert/convert_mdbnomics.m | 6 +-- .../octave_ver_less_than.m | 37 +++++++++++++++++++ 7 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 src/utilities/missing/octave_ver_less_than/octave_ver_less_than.m diff --git a/src/@dates/intersect.m b/src/@dates/intersect.m index df48770..d0af974 100644 --- a/src/@dates/intersect.m +++ b/src/@dates/intersect.m @@ -38,6 +38,8 @@ if ~isequal(o.freq,p.freq) return end +% Octave 6.1.0 added support for the 'legacy' option, but we don't use it +% because of this bug: https://savannah.gnu.org/bugs/?59708 if isoctave time = intersect(o.time,p.time,'rows'); else diff --git a/src/@dates/remove_.m b/src/@dates/remove_.m index 480560a..49463c2 100644 --- a/src/@dates/remove_.m +++ b/src/@dates/remove_.m @@ -42,7 +42,7 @@ if ~isequal(o.freq,p.freq) error('dates:remove','Inputs must have common frequency!') end -if isoctave +if isoctave && octave_ver_less_than('6') time = setdiff(o.time,p.time,'rows'); else time = setdiff(o.time,p.time,'rows','legacy'); diff --git a/src/@dates/setdiff.m b/src/@dates/setdiff.m index c368186..a800b45 100644 --- a/src/@dates/setdiff.m +++ b/src/@dates/setdiff.m @@ -48,7 +48,7 @@ if isequal(o.length(),p.length()) && isequal(o, p) return end -if isoctave +if isoctave && octave_ver_less_than('6') if nargout<2 time = setdiff(o.time,p.time,'rows'); else diff --git a/src/@dates/unique_.m b/src/@dates/unique_.m index fec7bd4..63a84be 100644 --- a/src/@dates/unique_.m +++ b/src/@dates/unique_.m @@ -30,7 +30,7 @@ if o.ndat()<=1 return end -if isoctave +if isoctave && octave_ver_less_than('6') [tmp, id, jd] = unique(o.time,'rows'); else [tmp, id, jd] = unique(o.time,'rows','legacy'); diff --git a/src/initialize_dseries_class.m b/src/initialize_dseries_class.m index 8d40df9..3154d63 100644 --- a/src/initialize_dseries_class.m +++ b/src/initialize_dseries_class.m @@ -56,6 +56,10 @@ if ~exist('matlab_ver_less_than','file') p{end+1} = 'utilities/missing/matlab_ver_less_than'; end +if ~exist('octave_ver_less_than','file') + p{end+1} = 'utilities/missing/octave_ver_less_than'; +end + if ~exist('demean','file') p{end+1} = 'utilities/missing/demean'; end diff --git a/src/utilities/convert/convert_mdbnomics.m b/src/utilities/convert/convert_mdbnomics.m index 7e22b22..2d489ea 100644 --- a/src/utilities/convert/convert_mdbnomics.m +++ b/src/utilities/convert/convert_mdbnomics.m @@ -29,7 +29,7 @@ end ds = dseries(); % Check for multiple datasets -if isoctave() +if isoctave && octave_ver_less_than('6') dataset_codes = unique(o.data(:,o.col_idx.dataset_code)); else dataset_codes = unique(o.data(:,o.col_idx.dataset_code),'stable'); @@ -39,7 +39,7 @@ end for ii = 1:length(dataset_codes) % Slice data for dataset ds_dataset = o.data(strcmp(o.data(:,o.col_idx.dataset_code),dataset_codes{ii}),:); - if isoctave() + if isoctave && octave_ver_less_than('6') series_codes = unique(ds_dataset(:,o.col_idx.series_code)); else series_codes = unique(ds_dataset(:,o.col_idx.series_code),'stable'); @@ -90,7 +90,7 @@ end % Add tags to the variables if length(dataset_codes) > 1 - if isoctave() + if isoctave && octave_ver_less_than('6') series_codes = unique(o.data(:,o.col_idx.series_code)); else series_codes = unique(o.data(:,o.col_idx.series_code),'stable'); diff --git a/src/utilities/missing/octave_ver_less_than/octave_ver_less_than.m b/src/utilities/missing/octave_ver_less_than/octave_ver_less_than.m new file mode 100644 index 0000000..0f4fc1f --- /dev/null +++ b/src/utilities/missing/octave_ver_less_than/octave_ver_less_than.m @@ -0,0 +1,37 @@ +function r = octave_ver_less_than(verstr) +% function r = octave_ver_less_than(verstr) +% +% Returns 1 if current Octave version is strictly older than +% the one given in argument. +% +% Note that this function will fail under Matlab. +% +% INPUTS +% verstr: a string of the format 'x.y' or 'x.y.z' +% +% OUTPUTS +% r: 0 or 1 +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2008-2019 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +r = compare_versions(version(), verstr, "<"); + +endfunction -- GitLab