Skip to content
Snippets Groups Projects
Commit 6a23afdd authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

RandStream: compatibility fix for MATLAB >= 7.12

setDefaultStream has been renamed setGlobalStream
getDefaultStream has been renamed getGlobalStream

Closes: #198
parent e0de9787
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ function [g,flag] = moment_function(xparams,sample_moments,dataset,options,paral ...@@ -15,7 +15,7 @@ function [g,flag] = moment_function(xparams,sample_moments,dataset,options,paral
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% The user has to provide a file where the moment conditions are defined. % The user has to provide a file where the moment conditions are defined.
% Copyright (C) 2010 Dynare Team % Copyright (C) 2010-2012 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -40,7 +40,11 @@ flag = 1; ...@@ -40,7 +40,11 @@ flag = 1;
if nargin<5 if nargin<5
if isempty(mainStream) if isempty(mainStream)
if matlab_ver_less_than('7.12')
mainStream = RandStream.getDefaultStream; mainStream = RandStream.getDefaultStream;
else
mainStream = RandStream.getGlobalStream;
end
mainState = mainStream.State; mainState = mainStream.State;
else else
mainStream.State = mainState; mainStream.State = mainState;
......
...@@ -2,7 +2,7 @@ function set_dynare_seed(a,b) ...@@ -2,7 +2,7 @@ function set_dynare_seed(a,b)
% Set seeds depending on matlab (octave) version. This routine is called in dynare_config and can be called by the % Set seeds depending on matlab (octave) version. This routine is called in dynare_config and can be called by the
% user in the mod file. % user in the mod file.
% %
% Copyright (C) 2010-2011 Dynare Team % Copyright (C) 2010-2012 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -32,12 +32,20 @@ if matlab_random_streams% Use new matlab interface. ...@@ -32,12 +32,20 @@ if matlab_random_streams% Use new matlab interface.
options_.DynareRandomStreams.algo = 'mt19937ar'; options_.DynareRandomStreams.algo = 'mt19937ar';
options_.DynareRandomStreams.seed = 0; options_.DynareRandomStreams.seed = 0;
s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed); s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed);
if matlab_ver_less_than('7.12')
reset(RandStream.setDefaultStream(s)); reset(RandStream.setDefaultStream(s));
else
reset(RandStream.setGlobalStream(s));
end
return return
end end
if ischar(a) && strcmpi(a,'reset') if ischar(a) && strcmpi(a,'reset')
s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed); s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed);
if matlab_ver_less_than('7.12')
reset(RandStream.setDefaultStream(s)); reset(RandStream.setDefaultStream(s));
else
reset(RandStream.setGlobalStream(s));
end
return return
end end
if ischar(a) if ischar(a)
...@@ -47,7 +55,11 @@ if matlab_random_streams% Use new matlab interface. ...@@ -47,7 +55,11 @@ if matlab_random_streams% Use new matlab interface.
options_.DynareRandomStreams.algo = 'mt19937ar'; options_.DynareRandomStreams.algo = 'mt19937ar';
options_.DynareRandomStreams.seed = a; options_.DynareRandomStreams.seed = a;
s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed); s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed);
if matlab_ver_less_than('7.12')
reset(RandStream.setDefaultStream(s)); reset(RandStream.setDefaultStream(s));
else
reset(RandStream.setGlobalStream(s));
end
return return
end end
elseif nargin==2 elseif nargin==2
...@@ -70,7 +82,11 @@ if matlab_random_streams% Use new matlab interface. ...@@ -70,7 +82,11 @@ if matlab_random_streams% Use new matlab interface.
options_.DynareRandomStreams.algo = a; options_.DynareRandomStreams.algo = a;
options_.DynareRandomStreams.seed = b; options_.DynareRandomStreams.seed = b;
s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed); s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed);
if matlab_ver_less_than('7.12')
reset(RandStream.setDefaultStream(s)); reset(RandStream.setDefaultStream(s));
else
reset(RandStream.setGlobalStream(s));
end
end end
else% Use old matlab interface. else% Use old matlab interface.
if nargin==1 if nargin==1
......
...@@ -14,7 +14,7 @@ function [param,sigma] = simulated_moments_estimation(dataset,options,parallel) ...@@ -14,7 +14,7 @@ function [param,sigma] = simulated_moments_estimation(dataset,options,parallel)
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% The user has to provide a file where the moment conditions are defined. % The user has to provide a file where the moment conditions are defined.
% Copyright (C) 2010-2011 Dynare Team % Copyright (C) 2010-2012 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -269,7 +269,11 @@ fprintf(fid,['tmp([' num2str(variance_idx) ']) = xparams(1:' int2str(nv) ').^2; ...@@ -269,7 +269,11 @@ fprintf(fid,['tmp([' num2str(variance_idx) ']) = xparams(1:' int2str(nv) ').^2;
fprintf(fid,'M_.Sigma_e = diag(tmp);') fprintf(fid,'M_.Sigma_e = diag(tmp);')
fprintf(fid,['stream=RandStream(''mt19937ar'',''Seed'',' int2str(slave_number) ');\n']); fprintf(fid,['stream=RandStream(''mt19937ar'',''Seed'',' int2str(slave_number) ');\n']);
if matlab_ver_less_than('7.12')
fprintf(fid,['RandStream.setDefaultStream(stream);\n\n']); fprintf(fid,['RandStream.setDefaultStream(stream);\n\n']);
else
fprintf(fid,['RandStream.setGlobalStream(stream);\n\n']);
end
fprintf(fid,['maxNumCompThreads(' int2str(threads_per_job) ');\n\n']); fprintf(fid,['maxNumCompThreads(' int2str(threads_per_job) ');\n\n']);
......
...@@ -15,7 +15,7 @@ function [r,flag] = smm_objective(xparams,sample_moments,weighting_matrix,option ...@@ -15,7 +15,7 @@ function [r,flag] = smm_objective(xparams,sample_moments,weighting_matrix,option
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% The user has to provide a file where the moment conditions are defined. % The user has to provide a file where the moment conditions are defined.
% Copyright (C) 2010 Dynare Team % Copyright (C) 2010-2012 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -40,7 +40,11 @@ flag = 1; ...@@ -40,7 +40,11 @@ flag = 1;
if nargin<5 if nargin<5
if isempty(mainStream) if isempty(mainStream)
if matlab_ver_less_than('7.12')
mainStream = RandStream.getDefaultStream; mainStream = RandStream.getDefaultStream;
else
mainStream = RandStream.getGlobalStream;
end
mainState = mainStream.State; mainState = mainStream.State;
else else
mainStream.State = mainState; mainStream.State = mainState;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment