From 58f96e10ef5b53d263fb207c61ed55b97dfdeb64 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Tue, 9 Jun 2015 10:31:51 +0200 Subject: [PATCH] remove ndat member, #4 --- src/@dates/append.m | 9 ++------- src/@dates/colon.m | 8 ++------ src/@dates/copy.m | 5 ++--- src/@dates/dates.m | 21 ++++++--------------- src/@dates/end.m | 4 ++-- src/@dates/eq.m | 4 ++-- src/@dates/ge.m | 16 ++++++++-------- src/@dates/gt.m | 20 ++++++++++---------- src/@dates/horzcat.m | 17 ++++++----------- src/@dates/intersect.m | 5 ++--- src/@dates/isempty.m | 8 ++++---- src/@dates/isequal.m | 4 ++-- src/@dates/le.m | 16 ++++++++-------- src/@dates/length.m | 6 +++--- src/@dates/lt.m | 20 ++++++++++---------- src/@dates/max.m | 7 +++---- src/@dates/min.m | 5 ++--- src/@dates/minus.m | 13 +++++-------- src/@dates/mtimes.m | 3 +-- src/@dates/ndat.m | 26 ++++++++++++++++++++++++++ src/@dates/ne.m | 4 ++-- src/@dates/plus.m | 11 ++++------- src/@dates/pop.m | 18 +++++++----------- src/@dates/remove.m | 5 ++--- src/@dates/setdiff.m | 5 ++--- src/@dates/sort.m | 12 +++++------- src/@dates/strings.m | 6 +++--- src/@dates/subsref.m | 23 +++++++++-------------- src/@dates/unique.m | 10 ++++------ 29 files changed, 144 insertions(+), 167 deletions(-) create mode 100644 src/@dates/ndat.m diff --git a/src/@dates/append.m b/src/@dates/append.m index f81740c..359cb0d 100644 --- a/src/@dates/append.m +++ b/src/@dates/append.m @@ -9,7 +9,7 @@ function o = append(o, d) % --*-- Unitary tests --*-- % OUTPUTS % - o [dates] dates object containing dates defined in o and d. -% Copyright (C) 2012-2014 Dynare Team +% Copyright (C) 2012-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 @@ -39,7 +39,6 @@ if ~isequal(o.freq, d.freq) error('dates:append:ArgCheck','dates must have common frequency!') end -o.ndat = o.ndat+1; o.time = [o.time; d.time]; %@test:1 @@ -53,7 +52,6 @@ o.time = [o.time; d.time]; %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2,B1); @@ -62,7 +60,6 @@ o.time = [o.time; d.time]; %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); %$ T = all(t); %@eof:1 @@ -77,7 +74,6 @@ o.time = [o.time; d.time]; %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2,B1); @@ -86,6 +82,5 @@ o.time = [o.time; d.time]; %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/colon.m b/src/@dates/colon.m index d8fb843..3cf5b7d 100644 --- a/src/@dates/colon.m +++ b/src/@dates/colon.m @@ -14,7 +14,7 @@ function q = colon(varargin) % --*-- Unitary tests --*-- % 1. p must be greater than o if d>0. % 2. p and q are dates objects with one element. -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -78,7 +78,6 @@ q.freq = o.freq; if isequal(q.freq, 1) % Yearly - q.ndat = m; q.time = NaN(m,2); q.time(:,1) = o.time(1)+transpose(0:d:n-1); q.time(:,2) = 1; @@ -106,9 +105,6 @@ else end if d>1 q.time = q.time(1:d:n,:); - q.ndat = m; - else - q.ndat = n; end end @@ -193,4 +189,4 @@ end %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); %$ T = all(t); -%$ @eof:4 \ No newline at end of file +%$ @eof:4 diff --git a/src/@dates/copy.m b/src/@dates/copy.m index 660ebbd..e15a508 100644 --- a/src/@dates/copy.m +++ b/src/@dates/copy.m @@ -8,7 +8,7 @@ function p = copy(o) % OUTPUTS % - p [dates] -% Copyright (C) 2014 Dynare Team +% Copyright (C) 2014-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 @@ -25,5 +25,4 @@ function p = copy(o) p = dates(); p.freq = o.freq; -p.ndat = o.ndat; -p.time = o.time; \ No newline at end of file +p.time = o.time; diff --git a/src/@dates/dates.m b/src/@dates/dates.m index d5da474..554d0ef 100644 --- a/src/@dates/dates.m +++ b/src/@dates/dates.m @@ -16,16 +16,14 @@ classdef dates<handle % along with Dynare. If not, see <http://www.gnu.org/licenses/>. properties - ndat = []; % Number of dates (integer scalar) freq = []; % Frequency (integer scalar) - time = []; % Array (ndat rows and two columns) + time = []; % Array (one row for every date. first column is the year, second is the period) end - + methods function o = dates(varargin) if ~nargin % Returns empty dates object. - o.ndat = 0; o.freq = NaN(0); o.time = NaN(0,2); return @@ -43,8 +41,7 @@ classdef dates<handle else error('dates:ArgCheck', 'All dates passed as inputs must have the same frequency!') end - o.ndat = length(tmp); - o.time = transpose(reshape([tmp.time],2,o.ndat)); + o.time = transpose(reshape([tmp.time], 2, length(tmp))); return end if isequal(nargin,1) && isfreq(varargin{1}) @@ -68,7 +65,6 @@ classdef dates<handle if isnumeric(varargin{3}) && isvector(varargin{3}) && all(isint(varargin{3})) if all(varargin{3}>=1) && all(varargin{3}<=o.freq) o.time = [varargin{2}(:), varargin{3}(:)]; - o.ndat = size(o.time,1); else error('dates:ArgCheck','Third input must contain integers between 1 and %i.', o.freq) end @@ -90,7 +86,6 @@ classdef dates<handle if isequal(o.freq, 1) if (isnumeric(varargin{2}) && isvector(varargin{2}) && all(isint(varargin{2}))) o.time = [varargin{2}, ones(length(varargin{2}),1)]; - o.ndat = size(o.time,1); return else error('dates:ArgCheck','Second input must be a vector of integers.') @@ -100,7 +95,6 @@ classdef dates<handle if all(isint(varargin{2}(:,1))) && all(isint(varargin{2}(:,1))) if all(varargin{2}(:,2)>=1) && all(varargin{2}(:,2)<=o.freq) o.time = [varargin{2}(:,1), varargin{2}(:,2)]; - o.ndat = size(o.time,1); else error('dates:ArgCheck','Second column of the last input must contain integers between 1 and %i.',o.freq) end @@ -129,7 +123,6 @@ end % classdef %$ % Define expected results. %$ e.time = [1945 3; 1950 2; 1950 1; 1953 4]; %$ e.freq = 4; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -137,7 +130,7 @@ end % classdef %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = dassert(d.ndat(),e.ndat()); %$ T = all(t); %@eof:1 @@ -151,7 +144,6 @@ end % classdef %$ % Define expected results. %$ e.time = [1945 3; 1950 2; 1950 10; 1953 12]; %$ e.freq = 12; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -159,7 +151,7 @@ end % classdef %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = dassert(d.ndat(),e.ndat()); %$ T = all(t); %@eof:2 @@ -173,7 +165,6 @@ end % classdef %$ % Define expected results. %$ e.time = [1945 1; 1950 1; 1950 1; 1953 1]; %$ e.freq = 1; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -181,7 +172,7 @@ end % classdef %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = dassert(d.ndat(),e.ndat()); %$ T = all(t); %@eof:3 diff --git a/src/@dates/end.m b/src/@dates/end.m index 6e6abdb..5de7f0b 100644 --- a/src/@dates/end.m +++ b/src/@dates/end.m @@ -10,7 +10,7 @@ function lastIndex = end(o, k, n) % OUTPUTS % lastIndex [integer] last dates index -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -26,4 +26,4 @@ function lastIndex = end(o, k, n) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. assert(k==1 && n==1, 'dates:end:ArgCheck', 'dates only has one dimension'); -lastIndex = o.ndat; \ No newline at end of file +lastIndex = o.ndat(); diff --git a/src/@dates/eq.m b/src/@dates/eq.m index 6986679..cb94169 100644 --- a/src/@dates/eq.m +++ b/src/@dates/eq.m @@ -9,7 +9,7 @@ function l = eq(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -26,7 +26,7 @@ function l = eq(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) +if isequal(o.ndat(), p.ndat()) l = logical(transpose(all(transpose(eq(o.time,p.time))))); else l = logical(transpose(all(transpose(bsxfun(@eq,o.time,p.time))))); diff --git a/src/@dates/ge.m b/src/@dates/ge.m index cf3d289..b4c41e5 100644 --- a/src/@dates/ge.m +++ b/src/@dates/ge.m @@ -9,7 +9,7 @@ function l = ge(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -26,21 +26,21 @@ function l = ge(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) +if isequal(o.ndat(), p.ndat()) l = (o==p); idx = find(l==false); for i=1:length(idx) l(idx(i)) = greaterorequal(o.time(idx(i),:), p.time(idx(i),:)); end else - if isequal(o.ndat,1) - l = false(p.ndat,1); - for i=1:p.ndat + if isequal(o.ndat(),1) + l = false(p.ndat(),1); + for i=1:p.ndat() l(i) = greaterorequal(o.time, p.time(i,:)); end else - l = false(o.ndat,1); - for i=1:o.ndat + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = greaterorequal(o.time(i,:), p.time); end end @@ -92,4 +92,4 @@ end %$ t(5) = dassert(dates(B5)>=dd,true(4,1)); %$ t(6) = dassert(dates(B1)>=dd,[true; false(3,1)]); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/gt.m b/src/@dates/gt.m index 36d553e..727aed0 100644 --- a/src/@dates/gt.m +++ b/src/@dates/gt.m @@ -9,7 +9,7 @@ function l = gt(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -26,20 +26,20 @@ function l = gt(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) - l = false(o.ndat,1); - for i=1:o.ndat +if isequal(o.ndat(), p.ndat()) + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = greaterthan(o.time(i,:), p.time(i,:)); end else - if isequal(o.ndat,1) - l = false(p.ndat,1); - for i=1:p.ndat + if isequal(o.ndat(),1) + l = false(p.ndat(),1); + for i=1:p.ndat() l(i) = greaterthan(o.time, p.time(i,:)); end else - l = false(o.ndat,1); - for i=1:o.ndat + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = greaterthan(o.time(i,:), p.time); end end @@ -89,4 +89,4 @@ end %$ t(5) = dassert(dates(B5)>dd,true(4,1)); %$ t(6) = dassert(dates(B1)>dd,false(4,1)); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/horzcat.m b/src/@dates/horzcat.m index b9217f5..dca4f2f 100644 --- a/src/@dates/horzcat.m +++ b/src/@dates/horzcat.m @@ -8,7 +8,7 @@ function o = horzcat(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - o [dates] object containing dates defined in varargin{:} -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -38,7 +38,6 @@ for i=2:n p = varargin{i}; if isequal(o.freq,p.freq) if ~isempty(p) - o.ndat = o.ndat + p.ndat; o.time = [o.time; p.time]; end else @@ -57,7 +56,6 @@ end %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2,B1); @@ -66,7 +64,7 @@ end %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1)==d.ndat(); %$ T = all(t); %@eof:1 @@ -81,7 +79,6 @@ end %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2); @@ -90,7 +87,7 @@ end %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1)==d.ndat(); %$ T = all(t); %@eof:2 @@ -105,7 +102,6 @@ end %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2); @@ -114,7 +110,7 @@ end %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1)==d.ndat(); %$ T = all(t); %@eof:3 @@ -129,7 +125,6 @@ end %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2); @@ -138,6 +133,6 @@ end %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1)==d.ndat(); %$ T = all(t); -%@eof:4 \ No newline at end of file +%@eof:4 diff --git a/src/@dates/intersect.m b/src/@dates/intersect.m index 738e32e..85d954e 100644 --- a/src/@dates/intersect.m +++ b/src/@dates/intersect.m @@ -9,7 +9,7 @@ function q = intersect(o, p) % --*-- Unitary tests --*-- % OUTPUTS % - q [dates] All the common elements in o and p. -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -51,7 +51,6 @@ end q.freq = o.freq; q.time = time; -q.ndat = rows(time); %@test:1 %$ % Define some dates objects @@ -67,4 +66,4 @@ q.ndat = rows(time); %$ t(1) = dassert(c1,d2); %$ t(2) = dassert(isempty(c2),true); %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 diff --git a/src/@dates/isempty.m b/src/@dates/isempty.m index cb10ef1..ba13962 100644 --- a/src/@dates/isempty.m +++ b/src/@dates/isempty.m @@ -8,7 +8,7 @@ function l = isempty(o) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -22,8 +22,8 @@ function l = isempty(o) % --*-- Unitary tests --*-- % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -l = isequal(o.ndat,0); + +l = isequal(o.ndat(),0); %@test:1 %$ % Instantiate an empty dates object @@ -39,4 +39,4 @@ l = isequal(o.ndat,0); %$ % Test if this object is empty %$ t(1) = ~isempty(d); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/isequal.m b/src/@dates/isequal.m index ca56605..bfd0784 100644 --- a/src/@dates/isequal.m +++ b/src/@dates/isequal.m @@ -9,7 +9,7 @@ function l = isequal(o, p, fake) % OUTPUTS % - l [logical] -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -33,7 +33,7 @@ if ~isequal(o.freq, p.freq) return end -if ~isequal(o.ndat, p.ndat) +if ~isequal(o.ndat(), p.ndat()) l = false; return end diff --git a/src/@dates/le.m b/src/@dates/le.m index 4d18b0b..d254407 100644 --- a/src/@dates/le.m +++ b/src/@dates/le.m @@ -9,7 +9,7 @@ function l = le(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -26,21 +26,21 @@ function l = le(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) +if isequal(o.ndat(), p.ndat()) l = (o==p); idx = find(l==0); for i=1:length(idx) l(idx(i)) = lessorequal(o.time(idx(i),:), p.time(idx(i),:)); end else - if isequal(o.ndat,1) - l = false(p.ndat,1); - for i=1:p.ndat + if isequal(o.ndat(),1) + l = false(p.ndat(),1); + for i=1:p.ndat() l(i) = lessorequal(o.time, p.time(i,:)); end else - l = false(o.ndat,1); - for i=1:o.ndat + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = lessorequal(o.time(i,:), p.time); end end @@ -92,4 +92,4 @@ end %$ t(5) = dassert(dates(B5)<=dd,false(4,1)); %$ t(6) = dassert(dates(B1)<=dd,true(4,1)); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/length.m b/src/@dates/length.m index a30111f..6ee6ae8 100644 --- a/src/@dates/length.m +++ b/src/@dates/length.m @@ -8,7 +8,7 @@ function n = length(o) % OUTPUTS % - n [integer] Number of elements in o. -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -23,7 +23,7 @@ function n = length(o) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -n = o.ndat; +n = o.ndat(); %@test:1 %$ d = dates('1938Q1'); @@ -44,4 +44,4 @@ n = o.ndat; %$ % Test if this object is empty %$ t(1) = isequal(d.length(),3); %$ T = all(t); -%@eof:3 \ No newline at end of file +%@eof:3 diff --git a/src/@dates/lt.m b/src/@dates/lt.m index 10b12bc..31bfb35 100644 --- a/src/@dates/lt.m +++ b/src/@dates/lt.m @@ -9,7 +9,7 @@ function l = lt(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -26,20 +26,20 @@ function l = lt(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) - l = false(o.ndat,1); - for i=1:o.ndat +if isequal(o.ndat(), p.ndat()) + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = lessthan(o.time(i,:),p.time(i,:)); end else - if isequal(o.ndat,1) - l = false(p.ndat,1); - for i=1:p.ndat + if isequal(o.ndat(),1) + l = false(p.ndat(),1); + for i=1:p.ndat() l(i) = lessthan(o.time,p.time(i,:)); end else - l = false(o.ndat,1); - for i=1:o.ndat + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = lessthan(o.time(i,:),p.time); end end @@ -89,4 +89,4 @@ end %$ t(5) = dassert(dates(B5)<dd,false(4,1)); %$ t(6) = dassert(dates(B1)<dd,[false; true(3,1)]); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/max.m b/src/@dates/max.m index 837071a..d5b43bc 100644 --- a/src/@dates/max.m +++ b/src/@dates/max.m @@ -8,7 +8,7 @@ function q = max(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - q [dates] -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -32,8 +32,7 @@ switch nargin sorted_time_member = sortrows(varargin{1}.time); q = dates(); q.freq = varargin{1}.freq; - q.ndat = 1; - q.time = sorted_time_member(varargin{1}.ndat,:); + q.time = sorted_time_member(varargin{1}.ndat(),:); otherwise q = max(horzcat(varargin{:})); end @@ -84,4 +83,4 @@ end %$ % Check the results. %$ t(1) = dassert(i,true); %$ T = all(t); -%@eof:4 \ No newline at end of file +%@eof:4 diff --git a/src/@dates/min.m b/src/@dates/min.m index 3cdbfa7..8fb3005 100644 --- a/src/@dates/min.m +++ b/src/@dates/min.m @@ -8,7 +8,7 @@ function q = min(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - q [dates] -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -32,7 +32,6 @@ switch nargin sorted_time_member = sortrows(varargin{1}.time); q = dates(); q.freq = varargin{1}.freq; - q.ndat = 1; q.time = sorted_time_member(1,:); otherwise q = min(horzcat(varargin{:})); @@ -84,4 +83,4 @@ end %$ % Check the results. %$ t(1) = dassert(i,true); %$ T = all(t); -%@eof:4 \ No newline at end of file +%@eof:4 diff --git a/src/@dates/minus.m b/src/@dates/minus.m index 5052028..011d2f3 100644 --- a/src/@dates/minus.m +++ b/src/@dates/minus.m @@ -18,7 +18,7 @@ function q = minus(o,p) % --*-- Unitary tests --*-- % p periods backward. % 3. If o is not a dates object, an error is returned. -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -44,11 +44,9 @@ if isa(o,'dates') && isa(p,'dates') v = copy(p); if ~isequal(u.length(),v.length()) if isequal(u.length(),1) - u.time = repmat(u.time,v.ndat,1); - u.ndat = v.ndat; + u.time = repmat(u.time,v.ndat(),1); elseif isequal(v.length(),1) - v.time = repmat(v.time,u.ndat,1); - v.ndat = u.ndat; + v.time = repmat(v.time,u.ndat(),1); else error('dates:minus:ArgCheck','Input arguments lengths are not consistent!') end @@ -59,11 +57,10 @@ if isa(o,'dates') && isa(p,'dates') q(id) = u.time(id,2)-v.time(id,2) + (u.time(id,1)-v.time(id,1))*v.freq; end elseif isa(o,'dates') && ~isa(p,'dates') - if (isvector(p) && isequal(length(p),o.ndat) && all(isint(p))) || (isscalar(p) && isint(p)) || (isequal(o.length(),1) && isvector(p) && all(isint(p))) + if (isvector(p) && isequal(length(p),o.ndat()) && all(isint(p))) || (isscalar(p) && isint(p)) || (isequal(o.length(),1) && isvector(p) && all(isint(p))) q = dates(); q.freq = o.freq; q.time = add_periods_to_array_of_dates(o.time, o.freq, -p(:)); - q.ndat = rows(q.time); else error('dates:minus:ArgCheck','Second argument has to be a vector of integers or scalar integer. You should read the manual.') end @@ -169,4 +166,4 @@ end %$ t(2) = dassert(e1,f1); %$ end %$ T = all(t); -%@eof:5 \ No newline at end of file +%@eof:5 diff --git a/src/@dates/mtimes.m b/src/@dates/mtimes.m index a83465b..b85703b 100644 --- a/src/@dates/mtimes.m +++ b/src/@dates/mtimes.m @@ -12,7 +12,7 @@ function p = mtimes(o,n) % --*-- Unitary tests --*-- % 1. If A = dates('2000Q1'), then B=A*3 is a dates object equal to dates('2000Q1','2000Q1','2000Q1') % 2. If A = dates('2003Q1','2009Q2'), then B=A*2 is a dates object equal to dates('2003Q1','2009Q2','2003Q1','2009Q2') -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -33,7 +33,6 @@ end p = copy(o); p.time = repmat(p.time, n, 1); -p.ndat = o.ndat*n; %@test:1 %$ % Define some dates diff --git a/src/@dates/ndat.m b/src/@dates/ndat.m new file mode 100644 index 0000000..e817626 --- /dev/null +++ b/src/@dates/ndat.m @@ -0,0 +1,26 @@ +function s = ndat(o) + +% Given a one element dates object, returns a string with the formatted date. +% +% INPUTS +% - o [dates] +% +% OUTPUTS +% - s [integer] + +% Copyright (C) 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/>. + +s = size(o.time, 1); diff --git a/src/@dates/ne.m b/src/@dates/ne.m index b8e2a68..351166e 100644 --- a/src/@dates/ne.m +++ b/src/@dates/ne.m @@ -9,7 +9,7 @@ function l = ne(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -26,7 +26,7 @@ function l = ne(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) +if isequal(o.ndat(), p.ndat()) l = logical(transpose(any(transpose(ne(o.time,p.time))))); else l = logical(transpose(any(transpose(bsxfun(@ne,o.time,p.time))))); diff --git a/src/@dates/plus.m b/src/@dates/plus.m index 1417d26..0ad0d43 100644 --- a/src/@dates/plus.m +++ b/src/@dates/plus.m @@ -14,7 +14,7 @@ function q = plus(o,p) % --*-- Unitary tests --*-- % 2. If one of the inputs is an integer or a vector of integers, the method shifts the dates % object by X (the interger input) periods forward. -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -45,22 +45,19 @@ if isa(o,'dates') && isa(p,'dates') q = dates(); q.freq = o.freq; q.time = [o.time; p.time]; - q.ndat = o.ndat+p.ndat; elseif isa(o,'dates') || isa(p,'dates') - if isa(o,'dates') && ((isvector(p) && isequal(length(p),o.ndat) && all(isint(p))) || ... + if isa(o,'dates') && ((isvector(p) && isequal(length(p),o.ndat()) && all(isint(p))) || ... (isequal(o.length(),1) && isvector(p) && all(isint(p))) || ... (isscalar(p) && isint(p))) q = dates(); q.freq = o.freq; q.time = add_periods_to_array_of_dates(o.time, q.freq, p(:)); - q.ndat = rows(q.time); - elseif isa(p,'dates') && ((isvector(o) && isequal(length(o),p.ndat) && all(isint(o))) || ... + elseif isa(p,'dates') && ((isvector(o) && isequal(length(o),p.ndat()) && all(isint(o))) || ... (isequal(p.length(),1) && isvector(o) && all(isint(o))) || ... (isscalar(o) && isint(o)) ) q = dates(); q.freq = p.freq; q.time = add_periods_to_array_of_dates(p.time, q.freq, o(:)); - q.ndat = rows(q.time); else error('dates:plus:ArgCheck','Please read the manual.') end @@ -150,4 +147,4 @@ end %$ t(6) = dassert(e5,f5); %$ end %$ T = all(t); -%@eof:3 \ No newline at end of file +%@eof:3 diff --git a/src/@dates/pop.m b/src/@dates/pop.m index 78da645..bc9c25a 100644 --- a/src/@dates/pop.m +++ b/src/@dates/pop.m @@ -15,7 +15,7 @@ function o = pop(o, p) % --*-- Unitary tests --*-- % % See also remove, setdiff. -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -36,7 +36,6 @@ end if nargin<2 % Remove last date - o.ndat = o.ndat-1; o.time = o.time(1:end-1,:); return end @@ -50,9 +49,8 @@ if ischar(p) end if isnumeric(p) - idx = find(transpose(1:o.ndat)~=p); + idx = find(transpose(1:o.ndat())~=p); o.time = o.time(idx,:); - o.ndat = o.ndat-1; else if ~isequal(o.freq,p.freq) error('dates:pop','Inputs must have common frequency!') @@ -64,9 +62,8 @@ else return end idx = find(o==p); - jdx = find(transpose(1:o.ndat)~=idx(end)); + jdx = find(transpose(1:o.ndat())~=idx(end)); o.time = o.time(jdx,:); - o.ndat = o.ndat-1; end %@test:1 @@ -80,7 +77,6 @@ end %$ % Define expected results %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine %$ d = dates(B4,B3,B2,B1); @@ -88,16 +84,16 @@ end %$ d.pop(); %$ t(1) = dassert(d.time,e.time(1:end-1,:)); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat-1); +%$ t(3) = size(e.time,1)-1==d.ndat(); %$ f = copy(d); %$ d.pop(B1); %$ t(4) = dassert(d.time,[1945 3; 1950 1; 1950 2]); %$ t(5) = dassert(d.freq,e.freq); -%$ t(6) = dassert(d.ndat,e.ndat-2); +%$ t(6) = size(e.time,1)-2==d.ndat(); %$ f.pop(dates(B1)); %$ t(7) = dassert(f.time,[1945 3; 1950 1; 1950 2]); %$ t(8) = dassert(f.freq,e.freq); -%$ t(9) = dassert(f.ndat,e.ndat-2); +%$ t(9) = size(e.time,1)-2==f.ndat(); %$ %$ % Check the results. %$ T = all(t); @@ -137,4 +133,4 @@ end %$ d.pop(1); %$ t(3) = isempty(d); %$ T = all(t); -%@eof:3 \ No newline at end of file +%@eof:3 diff --git a/src/@dates/remove.m b/src/@dates/remove.m index 54377e1..d11830a 100644 --- a/src/@dates/remove.m +++ b/src/@dates/remove.m @@ -15,7 +15,7 @@ function o = remove(o, p) % --*-- Unitary tests --*-- % % See also pop, setdiff -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -49,7 +49,6 @@ else end o.time = time; -o.ndat = rows(time); %@test:1 %$ % Define some dates objects @@ -77,4 +76,4 @@ o.ndat = rows(time); %$ % Check the results. %$ t(1) = dassert(d,f); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/setdiff.m b/src/@dates/setdiff.m index 8e5ef08..1abe694 100644 --- a/src/@dates/setdiff.m +++ b/src/@dates/setdiff.m @@ -11,7 +11,7 @@ function q = setdiff(o,p) % --*-- Unitary tests --*-- % % See also pop, remove. -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -51,7 +51,6 @@ if isempty(time) end q.time = time; -q.ndat = rows(time); %@test:1 %$ % Define some dates objects @@ -67,4 +66,4 @@ q.ndat = rows(time); %$ t(1) = dassert(c1,d2); %$ t(2) = dassert(isempty(c2),logical(1)); %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 diff --git a/src/@dates/sort.m b/src/@dates/sort.m index d1c0328..882decb 100644 --- a/src/@dates/sort.m +++ b/src/@dates/sort.m @@ -8,7 +8,7 @@ function o = sort(o) % --*-- Unitary tests --*-- % OUTPUTS % - o [dates] with dates sorted by increasing order. -% Copyright (C) 2011-2014 Dynare Team +% Copyright (C) 2011-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 @@ -23,7 +23,7 @@ function o = sort(o) % --*-- Unitary tests --*-- % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if isequal(o.ndat,1) +if isequal(o.ndat(),1) return end @@ -39,7 +39,6 @@ o.time = sortrows(o.time,[1,2]); %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4]; %$ e.freq = 4; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -48,7 +47,7 @@ o.time = sortrows(o.time,[1,2]); %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1) == d.ndat(); %$ T = all(t); %@eof:1 @@ -62,7 +61,6 @@ o.time = sortrows(o.time,[1,2]); %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4]; %$ e.freq = 4; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -71,6 +69,6 @@ o.time = sortrows(o.time,[1,2]); %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1) == d.ndat(); %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 diff --git a/src/@dates/strings.m b/src/@dates/strings.m index 0e3d47b..0198d15 100644 --- a/src/@dates/strings.m +++ b/src/@dates/strings.m @@ -8,7 +8,7 @@ function m = strings(o) % OUTPUTS % - m [cell of char] object with n elements. -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -23,8 +23,8 @@ function m = strings(o) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -m = cell(1,o.ndat); +m = cell(1,o.ndat()); for i = 1:o.length() m(i) = { date2string(o.time(i,:), o.freq) }; -end \ No newline at end of file +end diff --git a/src/@dates/subsref.m b/src/@dates/subsref.m index 8d8bb57..d442598 100644 --- a/src/@dates/subsref.m +++ b/src/@dates/subsref.m @@ -13,7 +13,7 @@ function B = subsref(A,S) % --*-- Unitary tests --*-- % 1. The type of the returned argument depends on the content of S. % 2. See the matlab's documentation about the subsref method. -% Copyright (C) 2011-2014 Dynare Team +% Copyright (C) 2011-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 @@ -31,12 +31,12 @@ function B = subsref(A,S) % --*-- Unitary tests --*-- switch S(1).type case '.' switch S(1).subs - case {'time','freq','ndat'}% Access public members. + case {'time','freq'}% Access public members. if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) error(['dates::subsref: ' S(1).subs ' is not a method but a member!']) end B = builtin('subsref', A, S(1)); - case {'sort','unique','double','isempty','length','char'}% Public methods (without input arguments) + case {'sort','unique','double','isempty','length','char','ndat'}% Public methods (without input arguments) B = feval(S(1).subs,A); if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) S = shiftS(S,1); @@ -94,7 +94,6 @@ switch S(1).type else error('dates::subsref: This is a bug!') end - B.ndat = rows(B.time); elseif isequal(length(S(1).subs),3) % If three inputs are provided, the second and third inputs are column verctors of integers (years and subperiods). if ~iscolumn(S(1).subs{2}) && ~all(isint(S(1).subs{2})) @@ -109,7 +108,6 @@ switch S(1).type error('dates::subsref: Second and third input arguments must have the same number of elements!') end B.time = [S(1).subs{2}, S(1).subs{3}]; - B.ndat = rows(B.time); else error('dates::subsref: Wrong calling sequence!') end @@ -130,7 +128,6 @@ switch S(1).type error('dates::subsref: First and second argument must have the same number of rows!') end B.time = [S(1).subs{1}, S(1).subs{2}]; - B.ndat = rows(B.time); elseif isequal(length(S(1).subs),1) [n, m] = size(S(1).subs{1}); if ~isequal(m,2) && ~isequal(B.freq,1) @@ -149,20 +146,18 @@ switch S(1).type else error('dates::subsref: This is a bug!') end - B.ndat = rows(B.time); else error('dates::subsref: Wrong number of inputs!') end end else % dates object A is not empty. We extract some dates - if isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) && all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.ndat) + if isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) && all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.ndat()) B = dates(); B.freq = A.freq; B.time = A.time(S(1).subs{1},:); - B.ndat = rows(B.time); else - error(['dates::subsref: indices has to be a vector of positive integers less than or equal to ' int2str(A.ndat) '!']) + error(['dates::subsref: indices has to be a vector of positive integers less than or equal to ' int2str(A.ndat()) '!']) end end otherwise @@ -190,7 +185,7 @@ end %$ if t(1) %$ t(2) = dassert(d.freq,B.freq); %$ t(3) = dassert(d.time,[1950 2; 1950 3]); -%$ t(4) = dassert(d.ndat,2); +%$ t(4) = dassert(d.ndat(),2); %$ end %$ T = all(t); %@eof:1 @@ -212,7 +207,7 @@ end %$ if t(1) %$ t(2) = dassert(d.freq,B.freq); %$ t(3) = dassert(d.time,[1950 2; 1950 3]); -%$ t(4) = dassert(d.ndat,2); +%$ t(4) = dassert(d.ndat(),2); %$ end %$ T = all(t); %@eof:2 @@ -234,7 +229,7 @@ end %$ if t(1) %$ t(2) = dassert(d.freq,B.freq); %$ t(3) = dassert(d.time,[1950 2; 1950 3]); -%$ t(4) = dassert(d.ndat,2); +%$ t(4) = dassert(d.ndat(),2); %$ end %$ T = all(t); %@eof:3 @@ -255,7 +250,7 @@ end %$ if t(1) %$ t(2) = dassert(d.freq,B.freq); %$ t(3) = dassert(d.time,[1950 2]); -%$ t(4) = dassert(d.ndat,1); +%$ t(4) = dassert(d.ndat(),1); %$ end %$ T = all(t); %@eof:4 diff --git a/src/@dates/unique.m b/src/@dates/unique.m index 1d74432..5ace4bd 100644 --- a/src/@dates/unique.m +++ b/src/@dates/unique.m @@ -11,7 +11,7 @@ function o = unique(o) % --*-- Unitary tests --*-- % REMARKS % 1. Only the last occurence of a date is kept. -% Copyright (C) 2013-2014 Dynare Team +% 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 @@ -26,7 +26,7 @@ function o = unique(o) % --*-- Unitary tests --*-- % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if o.ndat<=1 +if o.ndat()<=1 return end @@ -37,7 +37,6 @@ else end o.time = o.time(sort(id),:); -o.ndat = size(o.time,1); %@test:1 %$ % Define some dates @@ -50,7 +49,6 @@ o.ndat = size(o.time,1); %$ % Define expected results. %$ e.time = [1953 4; 1950 1; 1945 3; 1950 2]; %$ e.freq = 4; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4,B5); @@ -59,6 +57,6 @@ o.ndat = size(o.time,1); %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1) == d.ndat(); %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 -- GitLab