From 4a1b5eccb22362b5de03645959f5ceb764b6147c Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 8 Oct 2019 16:10:30 +0200 Subject: [PATCH] Support MATLAB namespaces in function calls #1639 shorten test names because adding `_namespace` made some .mod file names too long --- preprocessor | 2 +- tests/Makefile.am | 14 +++--- .../+namespace/extFunNoDerivsNamespace.m | 3 ++ .../extFunWithFirstAndSecondDerivsNamespace.m | 9 ++++ ...ided.mod => first_and_2nd_deriv_given.mod} | 0 ....mod => first_and_2nd_deriv_given_dll.mod} | 0 ...irst_and_2nd_deriv_given_dll_namespace.mod | 48 +++++++++++++++++++ .../first_and_2nd_deriv_given_namespace.mod | 48 +++++++++++++++++++ ...fcn_provided.mod => first_deriv_given.mod} | 0 ...ided_dll.mod => first_deriv_given_dll.mod} | 0 ...v_fcns_provided.mod => no_deriv_given.mod} | 0 ...rovided_dll.mod => no_deriv_given_dll.mod} | 0 12 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 tests/external_function/+matlab/+namespace/extFunNoDerivsNamespace.m create mode 100644 tests/external_function/+matlab/+namespace/extFunWithFirstAndSecondDerivsNamespace.m rename tests/external_function/{first_and_2nd_deriv_fcns_provided.mod => first_and_2nd_deriv_given.mod} (100%) rename tests/external_function/{first_and_2nd_deriv_fcns_provided_dll.mod => first_and_2nd_deriv_given_dll.mod} (100%) create mode 100644 tests/external_function/first_and_2nd_deriv_given_dll_namespace.mod create mode 100644 tests/external_function/first_and_2nd_deriv_given_namespace.mod rename tests/external_function/{first_deriv_fcn_provided.mod => first_deriv_given.mod} (100%) rename tests/external_function/{first_deriv_fcn_provided_dll.mod => first_deriv_given_dll.mod} (100%) rename tests/external_function/{no_deriv_fcns_provided.mod => no_deriv_given.mod} (100%) rename tests/external_function/{no_deriv_fcns_provided_dll.mod => no_deriv_given_dll.mod} (100%) diff --git a/preprocessor b/preprocessor index fac9e4436..9e454debb 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit fac9e4436c1c1f7d97e03d5fee77f7fb45dff54a +Subproject commit 9e454debb5eb7cbabcf29e844e16f2463d8d7eb6 diff --git a/tests/Makefile.am b/tests/Makefile.am index 1b6fef014..5b4698caa 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -173,12 +173,14 @@ MODFILES = \ dsge-var/simul_hybrid.mod \ dsge-var/dsgevar_forward_calibrated_lambda.mod \ dsge-var/dsgevar_forward_estimated_lambda.mod \ - external_function/first_and_2nd_deriv_fcns_provided.mod \ - external_function/first_and_2nd_deriv_fcns_provided_dll.mod \ - external_function/first_deriv_fcn_provided.mod \ - external_function/first_deriv_fcn_provided_dll.mod \ - external_function/no_deriv_fcns_provided.mod \ - external_function/no_deriv_fcns_provided_dll.mod \ + external_function/first_deriv_given.mod \ + external_function/first_deriv_given_dll.mod \ + external_function/first_and_2nd_deriv_given.mod \ + external_function/first_and_2nd_deriv_given_namespace.mod \ + external_function/first_and_2nd_deriv_given_dll.mod \ + external_function/first_and_2nd_deriv_given_dll_namespace.mod \ + external_function/no_deriv_given.mod \ + external_function/no_deriv_given_dll.mod \ seeds.mod \ identification/kim/kim2.mod \ identification/as2007/as2007.mod \ diff --git a/tests/external_function/+matlab/+namespace/extFunNoDerivsNamespace.m b/tests/external_function/+matlab/+namespace/extFunNoDerivsNamespace.m new file mode 100644 index 000000000..a05eb9861 --- /dev/null +++ b/tests/external_function/+matlab/+namespace/extFunNoDerivsNamespace.m @@ -0,0 +1,3 @@ +function y=extFunNoDerivsNamespace(a,b) +y=a*(b^2); +end \ No newline at end of file diff --git a/tests/external_function/+matlab/+namespace/extFunWithFirstAndSecondDerivsNamespace.m b/tests/external_function/+matlab/+namespace/extFunWithFirstAndSecondDerivsNamespace.m new file mode 100644 index 000000000..25d4a80f7 --- /dev/null +++ b/tests/external_function/+matlab/+namespace/extFunWithFirstAndSecondDerivsNamespace.m @@ -0,0 +1,9 @@ +function [y df d2f]=extFunWithFirstAndSecondDerivsNamespace(a,b) +y=a*(b^2); + +da=b^2; +db=2*a*b; +df=[da db]; + +d2f=[0 2*b; 2*b 2*a]; +end \ No newline at end of file diff --git a/tests/external_function/first_and_2nd_deriv_fcns_provided.mod b/tests/external_function/first_and_2nd_deriv_given.mod similarity index 100% rename from tests/external_function/first_and_2nd_deriv_fcns_provided.mod rename to tests/external_function/first_and_2nd_deriv_given.mod diff --git a/tests/external_function/first_and_2nd_deriv_fcns_provided_dll.mod b/tests/external_function/first_and_2nd_deriv_given_dll.mod similarity index 100% rename from tests/external_function/first_and_2nd_deriv_fcns_provided_dll.mod rename to tests/external_function/first_and_2nd_deriv_given_dll.mod diff --git a/tests/external_function/first_and_2nd_deriv_given_dll_namespace.mod b/tests/external_function/first_and_2nd_deriv_given_dll_namespace.mod new file mode 100644 index 000000000..a868c4193 --- /dev/null +++ b/tests/external_function/first_and_2nd_deriv_given_dll_namespace.mod @@ -0,0 +1,48 @@ +// Example 1 from Collard's guide to Dynare +var y, c, k, a, h, b; +varexo e, u; + +parameters beta, rho, alpha, delta, theta, psi, tau; + +alpha = 0.36; +rho = 0.95; +tau = 0.025; +beta = 0.99; +delta = 0.025; +psi = 0; +theta = 2.95; + +phi = 0.1; + +addpath(pwd) + +external_function(nargs=2, name=matlab.namespace.extFunWithFirstAndSecondDerivsNamespace, first_deriv_provided, second_deriv_provided); + +model(use_dll); +c*theta*h^(1+psi)=(1-alpha)*y; +k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) + *(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); +y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); +k = exp(b)*(y-c)+matlab.namespace.extFunWithFirstAndSecondDerivsNamespace((1-delta),k(-1)); +a = rho*a(-1)+tau*b(-1) + e; +b = tau*a(-1)+rho*b(-1) + u; +end; + +initval; +y = 1.08068253095672; +c = 0.80359242014163; +h = 0.29175631001732; +k = 11.08360443260358; +a = 0; +b = 0; +e = 0; +u = 0; +end; + +shocks; +var e; stderr 0.009; +var u; stderr 0.009; +var e, u = phi*0.009*0.009; +end; + +stoch_simul; diff --git a/tests/external_function/first_and_2nd_deriv_given_namespace.mod b/tests/external_function/first_and_2nd_deriv_given_namespace.mod new file mode 100644 index 000000000..1cefa8399 --- /dev/null +++ b/tests/external_function/first_and_2nd_deriv_given_namespace.mod @@ -0,0 +1,48 @@ +// Example 1 from Collard's guide to Dynare +var y, c, k, a, h, b; +varexo e, u; + +parameters beta, rho, alpha, delta, theta, psi, tau; + +alpha = 0.36; +rho = 0.95; +tau = 0.025; +beta = 0.99; +delta = 0.025; +psi = 0; +theta = 2.95; + +phi = 0.1; + +addpath(pwd) + +external_function(nargs=2, name=matlab.namespace.extFunWithFirstAndSecondDerivsNamespace, first_deriv_provided, second_deriv_provided); + +model; +c*theta*h^(1+psi)=(1-alpha)*y; +k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) + *(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); +y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); +k = exp(b)*(y-c)+matlab.namespace.extFunWithFirstAndSecondDerivsNamespace((1-delta),k(-1)); +a = rho*a(-1)+tau*b(-1) + e; +b = tau*a(-1)+rho*b(-1) + u; +end; + +initval; +y = 1.08068253095672; +c = 0.80359242014163; +h = 0.29175631001732; +k = 11.08360443260358; +a = 0; +b = 0; +e = 0; +u = 0; +end; + +shocks; +var e; stderr 0.009; +var u; stderr 0.009; +var e, u = phi*0.009*0.009; +end; + +stoch_simul; diff --git a/tests/external_function/first_deriv_fcn_provided.mod b/tests/external_function/first_deriv_given.mod similarity index 100% rename from tests/external_function/first_deriv_fcn_provided.mod rename to tests/external_function/first_deriv_given.mod diff --git a/tests/external_function/first_deriv_fcn_provided_dll.mod b/tests/external_function/first_deriv_given_dll.mod similarity index 100% rename from tests/external_function/first_deriv_fcn_provided_dll.mod rename to tests/external_function/first_deriv_given_dll.mod diff --git a/tests/external_function/no_deriv_fcns_provided.mod b/tests/external_function/no_deriv_given.mod similarity index 100% rename from tests/external_function/no_deriv_fcns_provided.mod rename to tests/external_function/no_deriv_given.mod diff --git a/tests/external_function/no_deriv_fcns_provided_dll.mod b/tests/external_function/no_deriv_given_dll.mod similarity index 100% rename from tests/external_function/no_deriv_fcns_provided_dll.mod rename to tests/external_function/no_deriv_given_dll.mod