Skip to content
Snippets Groups Projects
Commit 6cbe459a authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Efficiency change. Store a single matrix of data instead of vectors.

Normally it should still be possible to instantiate dseries objects
from mat files generated by previous versions of Dynare (before 4.6).
parent 06ab787f
Branches
No related tags found
No related merge requests found
Pipeline #2544 passed
......@@ -103,16 +103,12 @@ switch format
TEX__ = o.tex;
OPS__ = o.ops;
TAGS__ = o.tags;
str = [];
for v = 1:vobs(o)
str = sprintf('%s %s = o.data(:,%u);', str, o.name{v}, v);
end
eval(str);
DATA__ = o.data;
currentdirectorycontent = dir();
if ismember([basename, '.mat'], {currentdirectorycontent.name})
copyfile([basename, '.mat'], [basename, '.old.mat']);
end
save([basename '.mat'], 'INIT__', 'FREQ__', 'NAMES__', 'TEX__', 'OPS__', 'TAGS__', o.name{:});
save([basename '.mat'], 'INIT__', 'FREQ__', 'NAMES__', 'TEX__', 'OPS__', 'TAGS__', 'DATA__');
case 'csv'
currentdirectorycontent = dir();
if ismember([basename, '.csv'],{currentdirectorycontent.name})
......
......@@ -85,21 +85,28 @@ else
tags = struct();
end
data = [];
if isempty(varlist)
varlist = fieldnames(datafile);
end
for i=1:length(varlist)
try
tmp = datafile.(varlist{i});
if isvector(tmp)
data = [data, tmp(:)];
else
error('load_mat_file:: All the variables must be vectors (%s is not a vector)!', varlist{i})
if isfield(datafile,'DATA__')
data = datafile.DATA__;
datafile = rmfield(datafile, 'DATA__');
else
% Previously to dynare 4.6 variables were stored as vectors of
% common length in the mat file. This part of the code deals
% with mat files generated by these older versions of Dynare.
data = [];
if isempty(varlist)
varlist = fieldnames(datafile);
end
for i=1:length(varlist)
try
tmp = datafile.(varlist{i});
if isvector(tmp)
data = [data, tmp(:)];
else
error('load_mat_file:: All the variables must be vectors (%s is not a vector)!', varlist{i})
end
catch
error('load_mat_file:: All the vectors (variables) in %s must have the same number of rows (observations)!', inputname(1))
end
catch
error('load_mat_file:: All the vectors (variables) in %s must have the same number of rows (observations)!', inputname(1))
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment