Factorize test for normpdf(), normcdf(), erf() and trigonometric functions

Incidentally:
- add trigonometric tests for bytecode
- add back a test for pure M-files
pac-components
Sébastien Villemot 2021-12-07 16:54:07 +01:00
parent c07508a917
commit d69c14398d
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
6 changed files with 45 additions and 89 deletions

View File

@ -151,7 +151,9 @@ MODFILES = \
histval_initval_file/ramst_datafile.mod \
histval_initval_file/sim_exo_lead_lag.mod \
histval_initval_file/sim_exo_lead_lag_initvalf.mod \
ramst_normcdf_and_friends.mod \
ramst_normcdf_and_friends_mfile.mod \
ramst_normcdf_and_friends_use_dll.mod \
ramst_normcdf_and_friends_bytecode.mod \
ramst_vec.mod \
ramst_mshocks_vec.mod \
example1_varexo_det.mod \
@ -179,7 +181,6 @@ MODFILES = \
steady_state_operator/block.mod \
steady_state_operator/bytecode_test.mod \
block_bytecode/ireland.mod \
block_bytecode/ramst_normcdf_and_friends.mod \
block_bytecode/lola_solve_one_boundary.mod \
block_bytecode/lola_solve_one_boundary_mfs1.mod \
block_bytecode/lola_solve_one_boundary_mfs2.mod \
@ -1343,7 +1344,8 @@ EXTRA_DIST = \
solver-test-functions/trigonometric.m \
solver-test-functions/variablydimensioned.m \
solver-test-functions/watson.m \
solver-test-functions/wood.m
solver-test-functions/wood.m \
ramst_normcdf_and_friends.inc
if ENABLE_MATLAB
check-local: check-matlab

View File

@ -1,65 +0,0 @@
// Tests the normcdf(), normpdf() and erf() functions, in the static and the dynamic byecode file
var c k t u v;
varexo x;
parameters alph gam delt bet aa;
alph=0.5;
gam=0.5;
delt=0.02;
bet=0.05;
aa=0.5;
model(bytecode, block);
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
t = normcdf(x, 2, 3);
u = normpdf(x, 1, 0.5);
v = erf(x);
end;
initval;
x = 1;
k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
c = aa*k^alph-delt*k;
t = 0;
u = 0;
v = 0;
end;
steady(solve_algo=5);
//check;
shocks;
var x;
periods 1;
values 1.2;
end;
simul(periods=20, stack_solve_algo=5);
if(abs(oo_.steady_state(5) - erf(1)) > 1e-10)
error('Test failed in static bytecode for erf')
end
if (abs(oo_.endo_simul(5, 2) - erf(1.2)) > 1e-10)
error('Test failed in dynamic bytecode for erf')
end
if(abs(oo_.steady_state(4) - normpdf(1, 1, 0.5)) > 1e-10)
error('Test failed in static bytecode for normpdf')
end
if (abs(oo_.endo_simul(4, 2) - normpdf(1.2, 1, 0.5)) > 1e-10)
error('Test failed in dynamic bytecode for normpdf')
end
if (abs(oo_.steady_state(3) - normcdf(1, 2, 3)) > 1e-10)
error('Test failed in static bytecode for normcdf')
end
if (abs(oo_.endo_simul(3, 2) - normcdf(1.2, 2, 3)) > 1e-10)
error('Test failed in dynamic bytecode for normcdf')
end

View File

@ -1,4 +1,4 @@
// Tests the normcdf(), normpdf() and erf() functions, in the static M-file, and in a dynamic C-file
// Tests the normcdf(), normpdf(), erf() and trigonometric functions
var c k t u v sin_x cos_x tan_x asin_y acos_y atan_y;
varexo x y;
@ -10,7 +10,11 @@ delt=0.02;
bet=0.05;
aa=0.5;
model(use_dll);
@#if model_options == ""
model;
@#else
model(@{model_options});
@#endif
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
t = normcdf(x, 2, 3);
@ -50,86 +54,92 @@ end;
simul(periods=20);
if(abs(oo_.steady_state(5) - erf(1)) > 1e-10)
error('Test failed in static M-file for erf')
error('Test failed in static @{mode_name} for erf')
end
if (abs(oo_.endo_simul(5, 2) - erf(1.2)) > 1e-10)
error('Test failed in dynamic M-file for erf')
error('Test failed in dynamic @{mode_name} for erf')
end
if(abs(oo_.steady_state(4) - normpdf(1, 1, 0.5)) > 1e-10)
error('Test failed in static M-file for normpdf')
error('Test failed in static @{mode_name} for normpdf')
end
if (abs(oo_.endo_simul(4, 2) - normpdf(1.2, 1, 0.5)) > 1e-10)
error('Test failed in dynamic M-file for normpdf')
error('Test failed in dynamic @{mode_name} for normpdf')
end
if (abs(oo_.steady_state(3) - normcdf(1, 2, 3)) > 1e-10)
error('Test failed in static M-file for normcdf')
error('Test failed in static @{mode_name} for normcdf')
end
if (abs(oo_.endo_simul(3, 2) - normcdf(1.2, 2, 3)) > 1e-10)
error('Test failed in dynamic M-file for normcdf')
error('Test failed in dynamic @{mode_name} for normcdf')
end
sin_x_pos=strmatch('sin_x',M_.endo_names,'exact');
if(abs(oo_.steady_state(sin_x_pos) - sin(1)) > 1e-10)
error('Test failed in static M-file for sin')
error('Test failed in static @{mode_name} for sin')
end
if (abs(oo_.endo_simul(sin_x_pos, 2) - sin(1.2)) > 1e-10)
error('Test failed in dynamic M-file for sin')
error('Test failed in dynamic @{mode_name} for sin')
end
cos_x_pos=strmatch('cos_x',M_.endo_names,'exact');
if(abs(oo_.steady_state(cos_x_pos) - cos(1)) > 1e-10)
error('Test failed in static M-file for cos')
error('Test failed in static @{mode_name} for cos')
end
if (abs(oo_.endo_simul(cos_x_pos, 2) - cos(1.2)) > 1e-10)
error('Test failed in dynamic M-file for cos')
error('Test failed in dynamic @{mode_name} for cos')
end
tan_x_pos=strmatch('tan_x',M_.endo_names,'exact');
if(abs(oo_.steady_state(tan_x_pos) - tan(1)) > 1e-10)
error('Test failed in static M-file for tan')
error('Test failed in static @{mode_name} for tan')
end
if (abs(oo_.endo_simul(tan_x_pos, 2) - tan(1.2)) > 1e-10)
error('Test failed in dynamic M-file for tan')
error('Test failed in dynamic @{mode_name} for tan')
end
asin_y_pos=strmatch('asin_y',M_.endo_names,'exact');
if(abs(oo_.steady_state(asin_y_pos) - asin(0)) > 1e-10)
error('Test failed in static M-file for asin')
error('Test failed in static @{mode_name} for asin')
end
if (abs(oo_.endo_simul(asin_y_pos,1) - asin(0)) > 1e-10) || ...
(abs(oo_.endo_simul(asin_y_pos, 2) - asin(0.5)) > 1e-10) || ...
(abs(oo_.endo_simul(asin_y_pos, 3) - asin(1)) > 1e-10)
error('Test failed in dynamic M-file for asin')
error('Test failed in dynamic @{mode_name} for asin')
end
acos_y_pos=strmatch('acos_y',M_.endo_names,'exact');
if(abs(oo_.steady_state(acos_y_pos) - acos(0)) > 1e-10)
error('Test failed in static M-file for acos')
error('Test failed in static @{mode_name} for acos')
end
if (abs(oo_.endo_simul(acos_y_pos,1) - acos(0)) > 1e-10) || ...
(abs(oo_.endo_simul(acos_y_pos, 2) - acos(0.5)) > 1e-10) || ...
(abs(oo_.endo_simul(acos_y_pos, 3) - acos(1)) > 1e-10)
error('Test failed in dynamic M-file for acos')
error('Test failed in dynamic @{mode_name} for acos')
end
atan_y_pos=strmatch('atan_y',M_.endo_names,'exact');
if(abs(oo_.steady_state(atan_y_pos) - atan(0)) > 1e-10)
error('Test failed in static M-file for atan')
error('Test failed in static @{mode_name} for atan')
end
if (abs(oo_.endo_simul(atan_y_pos,1) - atan(0)) > 1e-10) || ...
(abs(oo_.endo_simul(atan_y_pos, 2) - atan(0.5)) > 1e-10) || ...
(abs(oo_.endo_simul(atan_y_pos, 3) - atan(1)) > 1e-10)
error('Test failed in dynamic M-file for atan')
end
error('Test failed in dynamic @{mode_name} for atan')
end
/*
Local Variables:
mode: dynare
End:
*/

View File

@ -0,0 +1,3 @@
@#define model_options = "bytecode"
@#define mode_name = "bytecode"
@#include "ramst_normcdf_and_friends.inc"

View File

@ -0,0 +1,3 @@
@#define model_options = ""
@#define mode_name = "M-file"
@#include "ramst_normcdf_and_friends.inc"

View File

@ -0,0 +1,3 @@
@#define model_options = "use_dll"
@#define mode_name = "MEX"
@#include "ramst_normcdf_and_friends.inc"