From ca2d99f09c6be4a94e2a1831779fa5ef3dbb6144 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 (manually cherry picked from commit 11e9e6089901faba7763e45d00ede420ef825f72) --- src/@dates/intersect.m | 2 + src/@dates/remove_.m | 4 +- src/@dates/setdiff.m | 2 +- src/@dates/unique_.m | 4 +- src/initialize_dseries_class.m | 4 ++ .../octave_ver_less_than.m | 37 +++++++++++++++++++ 6 files changed, 48 insertions(+), 5 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 5cbed03..658f4ba 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 || matlab_ver_less_than('8.1.0') time = intersect(o.time,p.time,'rows'); else diff --git a/src/@dates/remove_.m b/src/@dates/remove_.m index 5416231..3ba7efc 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 || matlab_ver_less_than('8.1.0') +if (isoctave && octave_ver_less_than('6')) || (~isoctave && matlab_ver_less_than('8.1.0')) time = setdiff(o.time,p.time,'rows'); else time = setdiff(o.time,p.time,'rows','legacy'); @@ -140,4 +140,4 @@ o.time = time; %$ end %$ %$ T = all(t); -%@eof:5 \ No newline at end of file +%@eof:5 diff --git a/src/@dates/setdiff.m b/src/@dates/setdiff.m index 783cbf9..55aa91a 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 || matlab_ver_less_than('8.1.0') +if (isoctave && octave_ver_less_than('6')) && (~isoctave && matlab_ver_less_than('8.1.0')) if nargout<2 time = setdiff(o.time,p.time,'rows'); else diff --git a/src/@dates/unique_.m b/src/@dates/unique_.m index dd14b4e..df0a121 100644 --- a/src/@dates/unique_.m +++ b/src/@dates/unique_.m @@ -30,7 +30,7 @@ if o.ndat()<=1 return end -if isoctave || matlab_ver_less_than('8.1.0') +if (isoctave && octave_ver_less_than('6')) && (~isoctave && matlab_ver_less_than('8.1.0')) [tmp, id, jd] = unique(o.time,'rows'); else [tmp, id, jd] = unique(o.time,'rows','legacy'); @@ -94,4 +94,4 @@ o.time = o.time(sort(id),:); %$ t(3) = dassert(d.freq,e.freq); %$ end %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 diff --git a/src/initialize_dseries_class.m b/src/initialize_dseries_class.m index 4a276fd..6ac9e8a 100644 --- a/src/initialize_dseries_class.m +++ b/src/initialize_dseries_class.m @@ -50,6 +50,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/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