Commit 34e5f487 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Use isdseries and fixed bug introduced in commit fbb38d55.

parent fbb38d55
......@@ -50,7 +50,7 @@ switch nargin
B.tex(i) = {['\sum_t ' B.tex{i}]};
end
case 2
if isa(varargin{2},'dseries')
if isdseries(varargin{2})
if ~isequal(varargin{1}.vobs, varargin{2}.vobs)
error('dseries::cumsum: First and second input arguments must be dseries objects with the same number of variables!')
end
......@@ -80,7 +80,7 @@ switch nargin
if ~isdates(varargin{2})
error('dseries::cumsum: Second input argument must be a dates object!')
end
if ~isa(varargin{3},'dseries')
if ~isdseries(varargin{3})
error('dseries::cumsum: Third input argument must be a dseries object!')
end
if ~isequal(varargin{1}.vobs, varargin{3}.vobs)
......
......@@ -94,7 +94,7 @@ switch nargin
% Create an empty dseries object.
return
case 1
if isa(varargin{1},'dates')
if isdates(varargin{1})
switch length(varargin{1})
case 0
error(['dseries::dseries: Input ' inputname(1) ' (identified as a dates object) must be non empty!'])
......@@ -177,7 +177,7 @@ switch nargin
if isdate(b)% Weekly, Monthly, Quaterly or Annual data.
ts.init = dates(b);
ts.freq = ts.init.freq;
elseif isa(b,'dates') && isequal(length(b),1)
elseif isdates(b) && isequal(length(b),1)
ts.freq = b.freq;
ts.init = b;
elseif isnumeric(b) && isscalar(b) && isint(b) % Yearly data.
......
......@@ -33,7 +33,7 @@ if nargin~=2
error('dseries::eq: I need exactly two input arguments!')
end
if ~(isa(A,'dseries') && isa(B,'dseries'))
if ~(isdseries(A) && isdseries(B))
error('dseries::eq: Both input arguments must be dseries objects!')
end
......
......@@ -30,7 +30,7 @@ if nargin~=2
error('dseries::isequal: I need exactly two input arguments!')
end
if ~isa(B,'dseries')
if ~isdseries(B)
error('dseries::isequal: Both input arguments must be dseries objects!')
end
......
......@@ -40,7 +40,7 @@ function A = merge(B,C) % --*-- 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 ~isa(C,'dseries')
if ~isdseries(C)
error('dseries::merge: Both inputs must be dseries objects!')
end
......
......@@ -40,7 +40,7 @@ function A = minus(B,C) % --*-- 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 isnumeric(B) && isreal(B) && isequal(length(B),1) && isa(C,'dseries')
if isnumeric(B) && isreal(B) && isequal(length(B),1) && isdseries(C)
A = dseries();
A.freq = C.freq;
A.init = C.init;
......@@ -57,7 +57,7 @@ if isnumeric(B) && isreal(B) && isequal(length(B),1) && isa(C,'dseries')
return;
end
if isnumeric(C) && isreal(C) && isequal(length(C),1) && isa(B,'dseries')
if isnumeric(C) && isreal(C) && isequal(length(C),1) && isdseries(B)
A = dseries();
A.freq = B.freq;
A.init = B.init;
......
......@@ -40,7 +40,7 @@ function A = mrdivide(B,C) % --*-- 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 isa(B,'dseries') && isa(C,'dseries')
if isdseries(B) && isdseries(C)
% Element by element divisions of two dseries object
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
......@@ -75,7 +75,7 @@ if isa(B,'dseries') && isa(C,'dseries')
A.tex(i) = {['(' B.tex{idB(i)} '/' C.tex{idC(i)} ')']};
end
A.data = bsxfun(@rdivide,B.data,C.data);
elseif isnumeric(C) && isreal(C) && isequal(length(C),1) && isa(B,'dseries')
elseif isnumeric(C) && isreal(C) && isequal(length(C),1) && isdseries(B)
% division of a dseries object by a real scalar.
A = dseries();
A.freq = B.freq;
......@@ -90,7 +90,7 @@ elseif isnumeric(C) && isreal(C) && isequal(length(C),1) && isa(B,'dseries')
A.tex(i) = {['(' B.tex{i} '/' num2str(C) ')']};
end
A.data = B.data/C;
elseif isnumeric(B) && isreal(B) && isequal(length(B),1) && isa(C,'dseries')
elseif isnumeric(B) && isreal(B) && isequal(length(B),1) && isdseries(C)
% division of a real scalar by a dseries object.
A = dseries();
A.freq = C.freq;
......
......@@ -40,7 +40,7 @@ function A = mtimes(B,C) % --*-- 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 isa(B,'dseries') && isa(C,'dseries')
if isdseries(B) && isdseries(C,'dseries')
% Element by element multiplication of two dseries object
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
......@@ -75,7 +75,7 @@ if isa(B,'dseries') && isa(C,'dseries')
A.tex(i) = {['(' B.tex{idB(i)} '*' C.tex{idC(i)} ')']};
end
A.data = bsxfun(@times,B.data,C.data);
elseif isnumeric(C) && isreal(C) && isequal(length(C),1) && isa(B,'dseries')
elseif isnumeric(C) && isreal(C) && isequal(length(C),1) && isdseries(B)
% Multiplication of a dseries object by a real scalar.
A = dseries();
A.freq = B.freq;
......@@ -90,7 +90,7 @@ elseif isnumeric(C) && isreal(C) && isequal(length(C),1) && isa(B,'dseries')
A.tex(i) = {['(' B.tex{i} '*' num2str(C) ')']};
end
A.data = B.data*C;
elseif isnumeric(B) && isreal(B) && isequal(length(B),1) && isa(C,'dseries')
elseif isnumeric(B) && isreal(B) && isequal(length(B),1) && isdseries(C)
% Multiplication of a dseries object by a real scalar.
A = dseries();
A.freq = C.freq;
......
......@@ -33,7 +33,7 @@ if nargin~=2
error('dseries::ne: I need exactly two input arguments!')
end
if ~(isa(A,'dseries') && isa(B,'dseries'))
if ~(isdseries(A) && isdseries(B))
error('dseries::ne: Both input arguments must be dseries objects!')
end
......
......@@ -41,7 +41,9 @@ function A = plus(B,C) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isscalar(B)
assert(isa(C, 'dseries'));
if ~isdseries(C)
error('dseries::plus: Second input argument must be a dseries object!')
end
b(1:size(C)) = B;
BB = dseries(b, C.dates(1));
BB.freq = C.freq;
......@@ -56,7 +58,9 @@ if isscalar(B)
end
if isscalar(C)
assert(isa(B, 'dseries'));
if ~isdseries(B)
error('dseries::plus: First input argument must be a dseries object!')
end
c(1:size(C)) = C;
CC = dseries(C, B.dates(1));
CC.freq = B.freq;
......@@ -67,7 +71,7 @@ if isscalar(C)
CC.tex = cell(CC.vobs,1);
CC.name(1) = {num2str(C)};
A = B + CC;
return;
return
end
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
......
......@@ -44,7 +44,7 @@ function A = set_names(B,varargin) % --*-- Unitary tests --*--
n = nargin-1;
if ~isa(B,'dseries')
if ~isdseries(B)
error(['dseries::rename: ' inputname(1) ' must be a dseries object!'])
end
......
......@@ -98,16 +98,16 @@ switch length(S)
end
end
case '.'
if isequal(S(1).subs,'init') && isa(B,'dates') && isequal(length(B),1)
if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1)
% Overwrite the init member...
A.init = B;
% ... and update freq and time members.
A.freq = A.init.freq;
A.time = A.init:A.init+(A.nobs-1);
A.dates = A.init:A.init+(A.nobs-1);
return
elseif isequal(S(1).subs,'time') && isa(B,'dates')
elseif isequal(S(1).subs,'dates') && isdates(B)
% Overwrite the time member...
A.time = B;
A.dates = B;
% ... and update the freq and init members.
A.init = B(1);
A.freq = A.init.freq;
......@@ -131,10 +131,10 @@ switch length(S)
end
end
case '()' % Date(s) selection
if isa(S(1).subs{1},'dates')
[junk, tdx] = intersect(A.time.time,S(1).subs{1}.time,'rows');
if isa(B,'dseries')
[junk, tdy] = intersect(B.time.time,S(1).subs{1}.time,'rows');
if isdates(S(1).subs{1})
[junk, tdx] = intersect(A.dates.time,S(1).subs{1}.time,'rows');
if isdseries(B)
[junk, tdy] = intersect(B.dates.time,S(1).subs{1}.time,'rows');
if isempty(tdy)
error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!')
end
......@@ -171,11 +171,11 @@ switch length(S)
else
sA = extract(A,S(1).subs);
end
if (isa(B,'dseries') && isequal(sA.vobs,B.vobs)) || (isnumeric(B) && isequal(sA.vobs,columns(B))) || (isnumeric(B) && isequal(columns(B),1))
if isa(S(2).subs{1},'dates')
[junk, tdx] = intersect(sA.time.time,S(2).subs{1}.time,'rows');
if isa(B,'dseries')
[junk, tdy] = intersect(B.time.time,S(2).subs{1}.time,'rows');
if (isdseries(B) && isequal(sA.vobs,B.vobs)) || (isnumeric(B) && isequal(sA.vobs,columns(B))) || (isnumeric(B) && isequal(columns(B),1))
if isdates(S(2).subs{1})
[junk, tdx] = intersect(sA.dates.time,S(2).subs{1}.time,'rows');
if isdseries(B)
[junk, tdy] = intersect(B.dates.time,S(2).subs{1}.time,'rows');
if isempty(tdy)
error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!')
end
......@@ -738,7 +738,7 @@ end
%$ t(6) = dyn_assert(ts1.name{3},'A3');
%$ t(7) = dyn_assert(ts1.data,A,1e-15);
%$ t(8) = dyn_assert(isequal(ts1.init,dd),1);
%$ t(9) = dyn_assert(isequal(ts1.time(1),dd),1);
%$ t(9) = dyn_assert(isequal(ts1.dates(1),dd),1);
%$ end
%$ T = all(t);
%@eof:19
......@@ -755,7 +755,7 @@ end
%$
%$ % modify first object.
%$ try
%$ ts1.time = dd:(dd+(ts1.nobs-1));
%$ ts1.dates = dd:(dd+(ts1.nobs-1));
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
......@@ -770,7 +770,7 @@ end
%$ t(6) = dyn_assert(ts1.name{3},'A3');
%$ t(7) = dyn_assert(ts1.data,A,1e-15);
%$ t(8) = dyn_assert(isequal(ts1.init,dd),1);
%$ t(9) = dyn_assert(isequal(ts1.time(1),dd),1);
%$ t(9) = dyn_assert(isequal(ts1.dates(1),dd),1);
%$ end
%$ T = all(t);
%@eof:20
\ No newline at end of file
......@@ -65,7 +65,7 @@ function B = subsref(A, S) % --*-- Unitary tests --*--
switch S(1).type
case '.'
switch S(1).subs
case {'data','nobs','vobs','name','tex','freq','time','init'} % Public members.
case {'data','nobs','vobs','name','tex','freq','dates','init'} % Public members.
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
error(['dseries::subsref: ' S(1).subs ' is not a method but a member!'])
end
......@@ -165,7 +165,7 @@ switch S(1).type
B.vobs = 1;
B.freq = A.freq;
B.init = A.init;
B.time = A.time;
B.dates = A.dates;
else
error('dseries::subsref: Unknown public method, public member or variable!')
end
......@@ -199,9 +199,9 @@ switch S(1).type
% Do nothing.
B = A;
end
elseif isa(S(1).subs{1},'dates')
elseif isdates(S(1).subs{1})
% Extract a subsample using a dates object
[junk,tdx] = intersect(A.time.time,S(1).subs{1}.time,'rows');
[junk,tdx] = intersect(A.dates.time,S(1).subs{1}.time,'rows');
B = dseries();
B.data = A.data(tdx,:);
B.name = A.name;
......@@ -210,7 +210,7 @@ switch S(1).type
B.vobs = A.vobs;
B.freq = A.freq;
B.init = A.init+(tdx(1)-1);
B.time = A.time(tdx,:);
B.dates = A.dates(tdx);
elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1}))
% Extract a subsample using a vector of integers (observation index).
% Note that this does not work if S(1).subs is an integer scalar... In which case S(1).subs is interpreted as a lead/lag operator (as in the Dynare syntax).
......@@ -223,8 +223,8 @@ switch S(1).type
B.nobs = size(B.data,1);
B.vobs = A.vobs;
B.freq = A.freq;
B.time = builtin('subsref', A.time, S(1));
B.init = B.time(1);
B.dates = builtin('subsref', A.dates, S(1));
B.init = B.dates(1);
B.name = A.name;
B.tex = A.tex;
else
......@@ -249,7 +249,7 @@ switch S(1).type
B.vobs = length(idx);
B.freq = A.freq;
B.init = A.init;
B.time = A.time;
B.dates = A.dates;
else
error('dseries::subsref: What the Hell are you tryin'' to do?!')
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment