RandStream: compatibility fix for MATLAB >= 7.12
setDefaultStream has been renamed setGlobalStream getDefaultStream has been renamed getGlobalStream Closes: #198time-shift
parent
e0de97878f
commit
6a23afdd48
|
@ -15,7 +15,7 @@ function [g,flag] = moment_function(xparams,sample_moments,dataset,options,paral
|
|||
% SPECIAL REQUIREMENTS
|
||||
% 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.
|
||||
%
|
||||
|
@ -40,7 +40,11 @@ flag = 1;
|
|||
|
||||
if nargin<5
|
||||
if isempty(mainStream)
|
||||
mainStream = RandStream.getDefaultStream;
|
||||
if matlab_ver_less_than('7.12')
|
||||
mainStream = RandStream.getDefaultStream;
|
||||
else
|
||||
mainStream = RandStream.getGlobalStream;
|
||||
end
|
||||
mainState = mainStream.State;
|
||||
else
|
||||
mainStream.State = mainState;
|
||||
|
|
|
@ -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
|
||||
% user in the mod file.
|
||||
%
|
||||
% Copyright (C) 2010-2011 Dynare Team
|
||||
% Copyright (C) 2010-2012 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -32,12 +32,20 @@ if matlab_random_streams% Use new matlab interface.
|
|||
options_.DynareRandomStreams.algo = 'mt19937ar';
|
||||
options_.DynareRandomStreams.seed = 0;
|
||||
s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed);
|
||||
reset(RandStream.setDefaultStream(s));
|
||||
if matlab_ver_less_than('7.12')
|
||||
reset(RandStream.setDefaultStream(s));
|
||||
else
|
||||
reset(RandStream.setGlobalStream(s));
|
||||
end
|
||||
return
|
||||
end
|
||||
if ischar(a) && strcmpi(a,'reset')
|
||||
s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed);
|
||||
reset(RandStream.setDefaultStream(s));
|
||||
if matlab_ver_less_than('7.12')
|
||||
reset(RandStream.setDefaultStream(s));
|
||||
else
|
||||
reset(RandStream.setGlobalStream(s));
|
||||
end
|
||||
return
|
||||
end
|
||||
if ischar(a)
|
||||
|
@ -47,7 +55,11 @@ if matlab_random_streams% Use new matlab interface.
|
|||
options_.DynareRandomStreams.algo = 'mt19937ar';
|
||||
options_.DynareRandomStreams.seed = a;
|
||||
s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed);
|
||||
reset(RandStream.setDefaultStream(s));
|
||||
if matlab_ver_less_than('7.12')
|
||||
reset(RandStream.setDefaultStream(s));
|
||||
else
|
||||
reset(RandStream.setGlobalStream(s));
|
||||
end
|
||||
return
|
||||
end
|
||||
elseif nargin==2
|
||||
|
@ -70,7 +82,11 @@ if matlab_random_streams% Use new matlab interface.
|
|||
options_.DynareRandomStreams.algo = a;
|
||||
options_.DynareRandomStreams.seed = b;
|
||||
s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed);
|
||||
reset(RandStream.setDefaultStream(s));
|
||||
if matlab_ver_less_than('7.12')
|
||||
reset(RandStream.setDefaultStream(s));
|
||||
else
|
||||
reset(RandStream.setGlobalStream(s));
|
||||
end
|
||||
end
|
||||
else% Use old matlab interface.
|
||||
if nargin==1
|
||||
|
|
|
@ -14,7 +14,7 @@ function [param,sigma] = simulated_moments_estimation(dataset,options,parallel)
|
|||
% SPECIAL REQUIREMENTS
|
||||
% 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.
|
||||
%
|
||||
|
@ -269,7 +269,11 @@ fprintf(fid,['tmp([' num2str(variance_idx) ']) = xparams(1:' int2str(nv) ').^2;
|
|||
fprintf(fid,'M_.Sigma_e = diag(tmp);')
|
||||
|
||||
fprintf(fid,['stream=RandStream(''mt19937ar'',''Seed'',' int2str(slave_number) ');\n']);
|
||||
fprintf(fid,['RandStream.setDefaultStream(stream);\n\n']);
|
||||
if matlab_ver_less_than('7.12')
|
||||
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']);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ function [r,flag] = smm_objective(xparams,sample_moments,weighting_matrix,option
|
|||
% SPECIAL REQUIREMENTS
|
||||
% 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.
|
||||
%
|
||||
|
@ -40,7 +40,11 @@ flag = 1;
|
|||
|
||||
if nargin<5
|
||||
if isempty(mainStream)
|
||||
mainStream = RandStream.getDefaultStream;
|
||||
if matlab_ver_less_than('7.12')
|
||||
mainStream = RandStream.getDefaultStream;
|
||||
else
|
||||
mainStream = RandStream.getGlobalStream;
|
||||
end
|
||||
mainState = mainStream.State;
|
||||
else
|
||||
mainStream.State = mainState;
|
||||
|
|
Loading…
Reference in New Issue