Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Dynare/dseries
  • sebastien/dseries
  • houtanb/dseries
  • wmutschl/dseries
  • DoraK/dseries
  • JohannesPfeifer/dseries
6 results
Show changes
Commits on Source (69)
Showing with 152 additions and 43 deletions
variables:
GIT_SUBMODULE_STRATEGY: normal
TERM: linux
MATLAB_VERSION: R2023a
OLD_MATLAB_VERSION: R2014a
MATLAB_VERSION: R2024b
OLD_MATLAB_VERSION: R2018b
# To ensure that "false && true" fails, see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/25394#note_412609647
FF_ENABLE_BASH_EXIT_CODE_CHECK: 'true'
before_script:
- git clone https://git.dynare.org/Dynare/m-unit-tests
......@@ -10,12 +12,12 @@ before_script:
test_matlab:
stage: test
script:
- make check-matlab MATLAB=/usr/local/MATLAB/$MATLAB_VERSION/bin/matlab
- make check-matlab MATLAB=/opt/MATLAB/$MATLAB_VERSION/bin/matlab
test_old_matlab:
stage: test
script:
- make check-matlab MATLAB=/usr/local/MATLAB/$OLD_MATLAB_VERSION/bin/matlab
- make check-matlab MATLAB=/opt/MATLAB/$OLD_MATLAB_VERSION/bin/matlab
test_octave:
stage: test
......
......@@ -11,7 +11,7 @@ check-octave: m-unit-tests/src/mtest.m
$(OCTAVE) --no-init-file --silent --no-history --eval "addpath([pwd() '/../m-unit-tests/src']); runalltests" && [ ! -f ./failed ] && [ -f ./pass ]
check-matlab: m-unit-tests/src/mtest.m
@$(MATLAB) -nosplash -nodisplay -r "addpath([pwd '/m-unit-tests/src']); cd tests; runalltests; quit" && [ ! -f ./tests/failed ] && [ -f ./tests/pass ]
@$(MATLAB) -batch "addpath([pwd '/m-unit-tests/src']); cd tests; runalltests; quit" && [ ! -f ./tests/failed ] && [ -f ./tests/pass ]
check-clean:
rm -f tests/*_test_*.m tests/*.csv tests/*.xls tests/*.xlsx tests/*.mat tests/failed tests/datafile_for_test
......
......@@ -73,7 +73,7 @@ fprintf(fid, '}\n');
fclose(fid);
% Run estimation of the ARIMA model
[status, result] = system(sprintf('%s %s', select_x13_binary(), basefilename));
system(sprintf('%s %s', select_x13_binary(), basefilename));
% Get the content of the generated *.est file
fid = fopen(sprintf('%s.est', basefilename), 'r');
......
function s = ndat(o)
% Given a one element dates object, returns a string with the formatted date.
% Returns the number of element in a dates object.
%
% INPUTS
% - o [dates]
%
% OUTPUTS
% - s [integer]
%
% REMARKS
% This method is deprecated, use length() instead
% Copyright © 2015-2022 Dynare Team
% Copyright © 2015-2024 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
......
......@@ -12,7 +12,7 @@ function [q, io] = setdiff(o, p)
%
% See also pop, remove.
% Copyright © 2013-2022 Dynare Team
% Copyright © 2013-2023 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
......@@ -27,7 +27,7 @@ function [q, io] = setdiff(o, p)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
if ~isa(o, 'dates') || ~isa(o, 'dates')
if ~isa(o, 'dates') || ~isa(p, 'dates')
error('dates:setdiff', 'All input arguments must be dates objects.')
end
......
......@@ -27,7 +27,7 @@ end
if vobs(o)-vobs(p)
if noinputname
error(['dseries::chain: dseries objects must have the same number of variables!'])
error('dseries::chain: dseries objects must have the same number of variables!')
else
error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have the same number of variables!'])
end
......@@ -35,7 +35,7 @@ end
if frequency(o)-frequency(p)
if noinputname
error(['dseries::chain: dseries objects must have common frequencies!'])
error('dseries::chain: dseries objects must have common frequencies!')
else
error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have common frequencies!'])
end
......
function [error_flag, message] = check(o)
% Copyright © 2013-2017 Dynare Team
% Copyright © 2013-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -21,7 +21,7 @@ error_flag = 0;
[n,m] = size(o.data);
if ~isequal(m, vobs(o));
if ~isequal(m, vobs(o))
error_flag = 1;
if nargout>1
message = ['dseries: Wrong number of variables in dseries object ''' inputname(1) '''!'];
......@@ -29,7 +29,7 @@ if ~isequal(m, vobs(o));
return
end
if ~isequal(n,nobs(o));
if ~isequal(n,nobs(o))
error_flag = 1;
if nargout>1
message = ['dseries: Wrong number of observations in dseries object ''' inputname(1) '''!'];
......@@ -37,7 +37,7 @@ if ~isequal(n,nobs(o));
return
end
if ~isequal(m,numel(o.name));
if ~isequal(m,numel(o.name))
error_flag = 1;
if nargout>1
message = ['dseries: Wrong number of variable names in dseries object ''' inputname(1) '''!'];
......@@ -45,7 +45,7 @@ if ~isequal(m,numel(o.name));
return
end
if ~isequal(m,numel(o.tex));
if ~isequal(m,numel(o.tex))
error_flag = 1;
if nargout>1
message = ['dseries: Wrong number of variable tex names in dseries object ''' inputname(1) '''!'];
......@@ -53,7 +53,7 @@ if ~isequal(m,numel(o.tex));
return
end
if ~isequal(numel(o.name), numel(o.tex));
if ~isequal(numel(o.name), numel(o.tex))
error_flag = 1;
if nargout>1
message = ['dseries: The number of variable tex names has to be equal to the number of variable names in dseries object ''' inputname(1) '''!'];
......@@ -61,7 +61,7 @@ if ~isequal(numel(o.name), numel(o.tex));
return
end
if ~isequal(numel(unique(o.name)), numel(o.name));
if ~isequal(numel(unique(o.name)), numel(o.name))
error_flag = 1;
if nargout>1
message = ['dseries: The variable names in dseries object ''' inputname(1) ''' are not unique!'];
......@@ -69,7 +69,7 @@ if ~isequal(numel(unique(o.name)), numel(o.name));
return
end
if ~isequal(numel(unique(o.tex)), numel(o.tex));
if ~isequal(numel(unique(o.tex)), numel(o.tex))
error_flag = 1;
if nargout>1
message = ['dseries: The variable tex names in dseries object ''' inputname(1) ''' are not unique!'];
......@@ -83,4 +83,4 @@ if ~isequal(o.dates, firstdate(o):firstdate(o)+nobs(o))
message = ['dseries: Wrong definition of the dates member in dseries object ''' inputname(1) '''!'];
end
return
end
\ No newline at end of file
end
function disp(o)
function disp(o, noname)
% Overloads disp method.
%
% INPUTS
% - o [dseries] Object to be displayed.
% - o [dseries] Object to be displayed.
% - noname [logical] Do not display the name of the dseries object if true. Default is false.
%
% OUTPUTS
% None
% Copyright © 2011-2017 Dynare Team
% Copyright © 2011-2024 Dynare Team
%
% This file is part of Dynare.
%
......@@ -25,6 +26,10 @@ function disp(o)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
if nargin<2
nonname = false;
end
vspace = ' ';
if ~vobs(o)
......@@ -35,9 +40,11 @@ end
separator = repmat(' | ', nobs(o)+1,1);
TABLE = ' ';
for t=1:nobs(o)
TABLE = char(TABLE, date2string(o.dates(t)));
end
for i = 1:vobs(o)
TABLE = horzcat(TABLE,separator);
tmp = o.name{i};
......@@ -46,8 +53,13 @@ for i = 1:vobs(o)
end
TABLE = horzcat(TABLE, tmp);
end
disp(vspace)
disp([inputname(1) ' is a dseries object:'])
disp(vspace);
if ~noname
disp([inputname(1) ' is a dseries object:'])
disp(vspace);
end
disp(TABLE);
disp(vspace);
\ No newline at end of file
disp(vspace);
......@@ -85,7 +85,7 @@ catch
end
if length(t)>1
t(2) = dassert(a,logical(ones(10,3)));
t(2) = dassert(a,true(10,3));
end
T = all(t);
%@eof:1
......@@ -28,7 +28,7 @@ function l = exist(o, varname)
if ~ischar(varname)
if isempty(inputname(2))
error(['dseries::exist: Input argument (variable name) has to be string!'])
error('dseries::exist: Input argument (variable name) has to be string!')
else
error(['dseries::exist: Second input argument ''' inputname(2) ''' has to be string!'])
end
......
......@@ -32,7 +32,7 @@ if iscell(name) & (rows(name)==1 || columns(name)==1)
for i=1:length(name)
id = find(strcmp(name{i}, o.name));
if isempty(id)
error('dseries::fill: Variable %s is unknown.', name)
error('dseries::fill: Variable %s is unknown.', name{i})
else
if isscalar(value)
o.data(:,id) = value;
......
......@@ -70,7 +70,7 @@ if t(1)
DATA = NaN(2,ts.vobs);
DATA = [DATA; 2*ones(ts.nobs-2,ts.vobs)];
t(2) = dassert(ts.data,DATA);
t(3) = dassert(ts.ops{1},['hdiff(H1)']);
t(3) = dassert(ts.ops{1},'hdiff(H1)');
end
T = all(t);
......@@ -91,7 +91,7 @@ if t(1)
DATA = NaN(6,ts.vobs);
DATA = [DATA; 6*ones(ts.nobs-6,ts.vobs)];
t(2) = dassert(ts.data,DATA);
t(3) = dassert(ts.ops{1},['hdiff(H1)']);
t(3) = dassert(ts.ops{1},'hdiff(H1)');
end
T = all(t);
......@@ -137,7 +137,7 @@ if t(1)
DATA = NaN(1,ts.vobs);
DATA = [DATA; ones(ts.nobs-1,ts.vobs)];
t(2) = dassert(ts.data,DATA);
t(3) = dassert(ts.ops{1},['hdiff(H1)']);
t(3) = dassert(ts.ops{1},'hdiff(H1)');
end
T = all(t);
......
......@@ -28,7 +28,7 @@ function o = hpcycle(o, lambda)
if nargin>1
if lambda<=0
error(['dseries::hpcycle: Lambda must be a positive integer!'])
error('dseries::hpcycle: Lambda must be a positive integer!')
end
else
lambda = [];
......
......@@ -28,7 +28,7 @@ function o = hpcycle_(o, lambda)
if nargin>1
if lambda<=0
error(['dseries::hpcycle: Lambda must be a positive integer!'])
error('dseries::hpcycle: Lambda must be a positive integer!')
end
else
lambda = [];
......
......@@ -28,7 +28,7 @@ function o = hptrend(o, lambda)
if nargin>1
if lambda<=0
error(['dseries::hptrend: Lambda must be a positive integer!'])
error('dseries::hptrend: Lambda must be a positive integer!')
end
else
lambda = [];
......
......@@ -28,7 +28,7 @@ function o = hptrend_(o, lambda)
if nargin>1
if lambda<=0
error(['dseries::hptrend: Lambda must be a positive integer!'])
error('dseries::hptrend: Lambda must be a positive integer!')
end
else
lambda = [];
......@@ -45,9 +45,9 @@ for i=1:vobs(o)
end
else
if isempty(lambda)
o.ops(i) = {sprintf('hptrend(%s, [])', o.name{i})};
o.ops(i) = {sprintf('hptrend(%s, [])', o.ops{i})};
else
o.ops(i) = {sprintf('hptrend(%s, %s)', o.name{i}, num2str(lambda))};
o.ops(i) = {sprintf('hptrend(%s, %s)', o.ops{i}, num2str(lambda))};
end
end
end
......@@ -64,7 +64,7 @@ stochastic_trend = cumsum(e);
deterministic_trend = .1*transpose(1:200);
x = zeros(200,1);
for i=2:200
x(i) = .75*x(i-1) + e(i);
x(i) = .75*x(i-1) + e(i);
end
y = x + stochastic_trend + deterministic_trend;
......
......@@ -39,7 +39,7 @@ end
if ~isequal(frequency(o),frequency(p))
if isempty(inputname(1))
error(['dseries::insert: dseries objects must have common frequencies!'])
error('dseries::insert: dseries objects must have common frequencies!')
else
error(['dseries::insert: ''' inputname(1) ''' and ''' inputname(2) ''' dseries objects must have common frequencies!'])
end
......
function [b, D] = lastobservedperiods(o)
% Return, for each variable, the last period without missing observations (last period without NaN).
%
% INPUTS
% - o [dseries] with N variables and T periods.
%
% OUTPUTS
% - b [struct] with N fields, each name field is a variable name and its content a date object.
% - D [dates] N elements.
% Copyright © 2023 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 <https://www.gnu.org/licenses/>.
d = cumprod(~isnan(o));
b = struct();
for i=1:o.vobs
b.(o.name{i}) = o.dates(find(d(:,i), 1, 'last'));
end
if nargout>1
D = dates(o.dates.freq);
for i=1:o.vobs
D.append_(b.(o.name{i}));
end
end
return % --*-- Unit tests --*--
%@test:1
try
a = randn(10, 3);
a(end,1) = NaN;
a(end,2) = NaN;
a(end-1,2) = NaN;
A = dseries(a, '2000Q1', {'A1', 'A2', 'A3'});
b = A.lastobservedperiods();
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = isequal(b.A1, dates('2002Q1'));
t(3) = isequal(b.A2, dates('2001Q4'));
t(4) = isequal(b.A3, dates('2002Q2'));
end
T = all(t);
%@eof:1
%@test:2
try
a = randn(10, 3);
a(end,1) = NaN;
a(end,2) = NaN;
a(end-1,2) = NaN;
A = dseries([a, a], '2000Q1', {'A1', 'A2', 'A3', 'B1', 'B2', 'B3'});
[b, D] = lastobservedperiods(A);
d = unique(D);
tmp = {};
for i=1:length(d)
tmp{i} = A(D==d(i));
end
t(1) = true;
catch
t(1) = false;
end
if t(1)
for i=1:length(d)
t(i+1) = isequal(tmp{i}.name,{sprintf('A%u', i); sprintf('B%u', i)});
end
end
T = all(t);
%@eof:2
......@@ -61,7 +61,7 @@ end
q = dseries();
[q.name, IBC, ~] = unique([o.name; p.name], 'last');
[q.name, IBC] = unique([o.name; p.name], 'last');
if ~legacy
[list_of_common_variables, iO, iP] = intersect(o.name, p.name);
......
......@@ -42,7 +42,7 @@ if isnumeric(p) && isvector(p) && isdseries(o) && length(p)==nobs(o)
if isempty(q.ops{i})
q.ops(i) = {sprintf('power(%s, %s)', q.name{i}, matrix2string(p))};
else
q.ops(i) = {sprintf('power(%s, %s)', q.name{i}, matrix2string(p))};
q.ops(i) = {sprintf('power(%s, %s)', q.ops{i}, matrix2string(p))};
end
end
return
......