From 62997c936f2a15ffc9baa20f1ec1512c4df7efb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= <stephane.adjemian@univ-lemans.fr> Date: Wed, 18 Nov 2015 14:39:25 +0100 Subject: [PATCH] Changed behaviour of the remove method... As in commit 6beaf7b00a9334ecd896508a48dfcf333d3c2002 (for the sort method). --- src/@dates/remove.m | 21 +++++------- src/@dates/remove_.m | 79 ++++++++++++++++++++++++++++++++++++++++++++ src/@dates/subsref.m | 2 +- 3 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 src/@dates/remove_.m diff --git a/src/@dates/remove.m b/src/@dates/remove.m index d11830a..721dbb7 100644 --- a/src/@dates/remove.m +++ b/src/@dates/remove.m @@ -42,25 +42,22 @@ if ~isequal(o.freq,p.freq) error('dates:remove','Inputs must have common frequency!') end -if isoctave || matlab_ver_less_than('8.1.0') - time = setdiff(o.time,p.time,'rows'); -else - time = setdiff(o.time,p.time,'rows','legacy'); -end - -o.time = time; +o = copy(o); +o.remove_(p); %@test:1 %$ % Define some dates objects %$ d = dates('1950Q1'):dates('1952Q4'); %$ e = dates('1951Q1'):dates('1952Q4'); %$ f = dates('1950Q1'):dates('1950Q4'); +%$ g = copy(d); %$ %$ % Call the tested routine. -%$ d.remove(e); -%$ +%$ c = d.remove(e); +%$ %$ % Check the results. -%$ t(1) = dassert(d,f); +%$ t(1) = dassert(c,f); +%$ t(2) = dassert(d,g); %$ T = all(t); %@eof:1 @@ -71,9 +68,9 @@ o.time = time; %$ f = dates('1950Q2'); %$ %$ % Call the tested routine. -%$ d.remove(e); +%$ c = d.remove(e); %$ %$ % Check the results. -%$ t(1) = dassert(d,f); +%$ t(1) = dassert(c,f); %$ T = all(t); %@eof:2 diff --git a/src/@dates/remove_.m b/src/@dates/remove_.m new file mode 100644 index 0000000..7fd5c77 --- /dev/null +++ b/src/@dates/remove_.m @@ -0,0 +1,79 @@ +function o = remove_(o, p) % --*-- Unitary tests --*-- + +% remove method for dates class (removes dates). +% +% INPUTS +% - o [dates] +% - p [dates] +% +% OUTPUTS +% - o [dates] +% +% REMARKS +% 1. If a is a date appearing more than once in o, then all occurences are removed. +% 2. The removal of p is done by inplace modification of o (in place version of setdiff). +% +% See also pop, setdiff + +% Copyright (C) 2013-2015 Dynare Team +% +% This code 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 dates submodule 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/>. + +if nargin<2 + error('dates:remove','Input argument is missing! You should read the manual') +end + +if ~isdates(p) + error('dates:remove','Input argument %s has to be a dates object') +end + +if ~isequal(o.freq,p.freq) + error('dates:remove','Inputs must have common frequency!') +end + +if isoctave || matlab_ver_less_than('8.1.0') + time = setdiff(o.time,p.time,'rows'); +else + time = setdiff(o.time,p.time,'rows','legacy'); +end + +o.time = time; + +%@test:1 +%$ % Define some dates objects +%$ d = dates('1950Q1'):dates('1952Q4'); +%$ e = dates('1951Q1'):dates('1952Q4'); +%$ f = dates('1950Q1'):dates('1950Q4'); +%$ +%$ % Call the tested routine. +%$ d.remove_(e); +%$ +%$ % Check the results. +%$ t(1) = dassert(d,f); +%$ T = all(t); +%@eof:1 + +%@test:2 +%$ % Define some dates objects +%$ d = dates('1950Q1','1950Q2','1950Q1'); +%$ e = dates('1950Q1'); +%$ f = dates('1950Q2'); +%$ +%$ % Call the tested routine. +%$ d.remove_(e); +%$ +%$ % Check the results. +%$ t(1) = dassert(d,f); +%$ T = all(t); +%@eof:2 \ No newline at end of file diff --git a/src/@dates/subsref.m b/src/@dates/subsref.m index 475d93d..e961d70 100644 --- a/src/@dates/subsref.m +++ b/src/@dates/subsref.m @@ -41,7 +41,7 @@ switch S(1).type if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) S = shiftS(S,1); end - case {'append','append_','pop','pop_','remove'}% Public methods (with arguments). + case {'append','append_','pop','pop_','remove','remove_'}% Public methods (with arguments). if isequal(S(2).type,'()') B = feval(S(1).subs,A,S(2).subs{:}); S = shiftS(S,1); -- GitLab