Commit Graph

562 Commits (2b3519e3b07a0c6fb736524cfdca45a551591d7e)

Author SHA1 Message Date
Houtan Bastani 6e680c0159
simplify in accordance with 02ae0af3e5 2019-01-29 17:52:19 +01:00
Houtan Bastani 302fec4dec
remove comparisons to nullptr 2019-01-29 17:46:09 +01:00
Houtan Bastani 02ae0af3e5
change map type for readability 2019-01-29 17:43:17 +01:00
Houtan Bastani 1e071ca499
make simplifications in dynamic model before copying to original 2019-01-28 17:53:04 +01:00
Houtan Bastani 90c45b2cd6
remove unused function added in d922ae8ffc 2019-01-28 15:34:38 +01:00
Houtan Bastani f5df7e7567
when an equation is of the form `X` = `constant`, replace all occurrences of `X` in other equations with `constant` 2019-01-28 15:32:12 +01:00
Sébastien Villemot c5fc2e38c1
Simplify log(1/x) into -log(x) (and similarly for log10) 2019-01-28 15:15:58 +01:00
Houtan Bastani 71be51c464
pac_growth: ensure symbol has been declared 2019-01-28 10:45:48 +01:00
Houtan Bastani d922ae8ffc
pac_model: permit lag on growth option 2019-01-25 14:52:26 +01:00
Houtan Bastani 9c95bfa33f
fix typos 2019-01-18 12:48:45 +01:00
Houtan Bastani 027b59b449
fix typos 2019-01-18 12:36:19 +01:00
Houtan Bastani a3e7547857
fix bug when defining variable with value on the command line with -D option (problem introduced in ee5fc6b16b) 2019-01-16 11:51:14 +01:00
Sébastien Villemot e7c9c26d2d
More modernizations with clang-tidy 2019-01-15 11:08:47 +01:00
Sébastien Villemot 4f9b384984
Use C++11 override keyword 2019-01-09 15:43:46 +01:00
Houtan Bastani 4c71d143f3
substitute leads/lags appropriately when identification or sensitivity statements are present. Issue: https://git.dynare.org/Dynare/dynare/issues/1631 2019-01-09 14:48:25 +01:00
Houtan Bastani 280b764ca5
onlymodel: read estimated_params block as well 2018-12-27 19:07:51 +01:00
Houtan Bastani 7d37c35a3d
onlymodel: read initval and endval too 2018-12-27 12:06:39 +01:00
Sébastien Villemot f2b0bdf0a2
Fix bug when histval is used and there is no auxiliary variable
Problem introduced in a69c65361c.
2018-12-20 17:45:54 +01:00
Sébastien Villemot 01385d1f80
Simplify implementation of nopreprocessoroutput option
Simply redirect cout to /dev/null, instead of propagating a boolean
everywhere.
2018-12-20 17:08:45 +01:00
Sébastien Villemot 5784dce1ca
Remove the possibility of passing the mod-file as a string in the first shell argument
This feature is ill-designed and no longer needed by the GUI. And is not very
useful: it is not possible to interact with the preprocessor without using the
filesystem, since the preprocessor creates many files anyways.

If we really need to reimplement such a feature, it should rather be redesigned
by reading the modfile from standard input (cin). That could be triggered by
using "-" as the filename argument (as is already done by several standard Unix
utilities).
2018-12-20 17:08:05 +01:00
Sébastien Villemot b2e3a481e3
Fix for histval with auxiliary lead variables corresponding to non-linear terms
The M_.params structure was not correctly passed to
dynamic_set_auxiliary_series.m, leading to crashes if a parameter was needed to
compute an auxiliary variable (typically an auxiliayr lead variable
corresponding to a non-linear term in stochastic setup).
2018-12-20 15:05:18 +01:00
Sébastien Villemot a69c65361c
Fix ramsey_policy with histval
Since 38152c34a4, the M_.endo_histval variable is
generated via dynamic_set_auxiliary_dseries.m. But the latter file does not
handle auxiliary variables for Lagrange multiplier. We therefore now set them
by hand (at an initial value of zero).
2018-12-20 15:05:18 +01:00
Sébastien Villemot 9e66627375
Fix for histval block in the presence of auxiliary lead variables
Since 38152c34a4, the M_.endo_histval variable is
generated via dynamic_set_auxiliary_dseries.m. The problem is that, for
auxiliary variables corresponding to a lead, this will generate a NaN in
M_.endo_histval. This is conceptually correct, since such variables are never
used as initial conditions, but this is inconsistent with what we do with the
"initval" block, and leads to crashes in some routines where we fail when there
is a NaN. Therefore, replace these with a zero, as it used to be.
2018-12-20 15:05:17 +01:00
Stéphane Adjemia (Scylla) 8b81474a2e
On macOS use gcc-7 from homebrew instead of gcc-clang.
To install this version of gcc:

~$ brew install gcc@7

Does not seem to work with gcc-8 (missing headers…).
2018-12-20 14:38:37 +01:00
Houtan Bastani ea76bc8636
epilogue: use different syntax for firstobservedperiod call 2018-12-19 16:20:30 +01:00
Sébastien Villemot 1393bf1d7e
Parse the options list at the top of the mod-file
Ref Dynare/dynare#1630
2018-12-19 16:14:40 +01:00
Houtan Bastani bb624ec6a7
epilogue: allow for simulations in epilogue block 2018-12-19 16:09:30 +01:00
Sébastien Villemot 38152c34a4
Make histval compatible with diff operator
The idea is to make use of the dynamic_set_auxiliary_dseries.m file to generate
the initial conditions for all auxiliary variables, including the diffs.

Also remove the check done by the preprocessor for the lags in histval, since
it does not work correctly with the diff operator.
2018-12-11 17:32:05 +01:00
Houtan Bastani aad8414f94
allow the use of previously assigned variables in epilogue block in later equations in epilogue block 2018-12-10 16:30:19 +01:00
Houtan Bastani 9d3f104b8c
fix epilogue block 2018-12-10 12:27:27 +01:00
Sébastien Villemot 82b1467074
Improve consistency of ExprNode methods for calculating max lead/lag
- ExprNode::maxLag() and ExprNode::maxLead() now take into account exogenous
  deterministic variables, for consistency with M_.maximum_{lead,lag}

- ExprNode::maxLag() no longer behaves as if diff() operators were
  expanded (i.e. it now returns 1 on diff(x(-1))), for consistency with
  maxEndoLag() and maxExoLag()

- New ExprNode::maxLagWithDiffsExpanded() method, that behaves as maxLag() used
  to behave (except that it also takes exogenous deterministic into account)
2018-12-05 15:30:03 +01:00
Sébastien Villemot fe6d4e9bca
Modify semantics of ExprNode::countDiffs()
Previously, this function was counting the total number of diff() operators in
an expression. But this is not very useful, and is potentially misleading,
because in practice we use this function to compute the maximum lag on
variables in levels.

This function now returns the maximum number of nested diffs.

For example, on diff(x)+diff(diff(y)), this function was returning 3, and it
now returns 2.
2018-12-05 12:41:13 +01:00
Sébastien Villemot 66a766b0b7
Small modernization 2018-12-04 18:41:04 +01:00
Sébastien Villemot 8bda21c504
Remove workaround for Bison 3.2
This was a bug, now fixed in Bison 3.2.2. The latter version is now available
on most platforms (Debian unstable/testing, Homebrew, MSYS2).
2018-12-04 17:10:34 +01:00
Sébastien Villemot 018068de91
Fix typo 2018-12-03 17:29:53 +01:00
Sébastien Villemot a08ce3de2b
Yet more simplifactions using std::tuple 2018-12-03 16:07:13 +01:00
Sébastien Villemot 571b5d0816
Computation of temporary terms generalized to any derivation order 2018-11-30 12:22:13 +01:00
Sébastien Villemot 67ac4bf8ea
Allow diff() and log() in "expression" option of var_expectation_model 2018-11-29 16:01:49 +01:00
Sébastien Villemot e9341c7153
Implement option "expression" of var_expectation_model
The data structure written in the driver file is changed also in the case of
the "variable" option.
2018-11-28 17:33:59 +01:00
Sébastien Villemot b88e0de53f
Remove useless accessor methods for data members that are const in ExprNode classes
Those const data members are simply made public.
2018-11-28 14:35:30 +01:00
Sébastien Villemot cac65b071e
Fix visibility of matchVTCTPHelper method in subclasses of ExprNode 2018-11-28 14:18:08 +01:00
Houtan Bastani 41af0841c3
extend nopreprocessoroutput option to substitution output 2018-11-28 11:53:50 +01:00
Sébastien Villemot 16a97a96fd
Rewrite engine for matching the non-optimizing agents part in PAC
The engine is now more robust and should reject any expression that does not
conform to the expected form. It is also able to deal with more cases, such as
terms appearing with a minus sign, or variables in the middle of a
three-factors product.

BTW, use a std::tuple for storing the result of the matching inside
PacExpectationNode, and change the order of components within the
structure (variable first, scalar last).
2018-11-27 19:03:35 +01:00
Sébastien Villemot 003df49e7d
Remove useless "virtual" keyword in various ExprNode methods 2018-11-27 09:50:41 +01:00
Sébastien Villemot fa039b8c41
Fix bug in block decomposition with treatment of varexo_det 2018-11-23 17:39:18 +01:00
Sébastien Villemot d733f3fb5a
Various simplifications and modernizations of the block/bytecode part 2018-11-23 17:19:59 +01:00
Sébastien Villemot fc9cc2dc50
Output symmetric elements in derivatives of hessian w.r.t. parameters
The preprocessor now writes all the symmetric elements in the "hp"
matrix (derivatives of the hessian w.r.t. parameters), for consistency with all
other derivatives output.

Previously it was only writing one of the two symmetric elements, when indices
of endogenous were different.
2018-11-22 17:51:14 +01:00
Sébastien Villemot e3a3992c1c
Derivation engine w.r.t. parameters generalized to any order
Also, no longer compute two times symmetric elements in derivation w.r.t.
parameters at order 2, for consistency with derivation w.r.t. endogenous.
It is therefore now necessary to duplicate them in the output to keep behavior
unchanged.
2018-11-22 17:13:55 +01:00
Sébastien Villemot 6fa115aedd
Derivation engine w.r.t. endogenous generalized to any order 2018-11-22 17:13:55 +01:00
Sébastien Villemot b7d50560f8
Move ModelTree constructor up in the file for clarity 2018-11-22 17:13:55 +01:00
Sébastien Villemot dfe1a005af
Bison bug has been fixed in 3.2.2 2018-11-22 11:46:36 +01:00
Sébastien Villemot fb883bbfb0
Small simplification of Bison file
Thanks to Akim Demaille for the suggestion.
2018-11-21 14:38:06 +01:00
Sébastien Villemot f01c4f85c2
Fix Julia bug introduced in previous commit 2018-11-19 16:39:05 +01:00
Sébastien Villemot 33994dde03
Optimization for use_dll at 2nd and 3rd order
When creating the sparse matrix (in MATLAB or C mode), since storage is in
column-major order, output the first column, then the second, then the third.
This gives a significant performance boost in use_dll mode (at both compilation
and runtime), because it facilitates memory accesses and expression reusage.
2018-11-19 16:03:47 +01:00
Sébastien Villemot b524e19cde
Remove duplicate storage of temp terms for params derivs in ModelTree 2018-11-16 18:26:36 +01:00
Sébastien Villemot e9b5f239df
Properly deal with model local variables in params derivatives file
Closes #13
2018-11-16 18:26:11 +01:00
Sébastien Villemot 3d2125287a
Temporary terms: various simplifications and added comments 2018-11-16 17:11:06 +01:00
Sébastien Villemot e89dd9cb8b
Make storage of derivatives ready for k-order
This is the first step towards computing k-order derivatives.

Ref Dynare/dynare#217, #10
2018-11-15 17:48:46 +01:00
Houtan Bastani 3eff2b91c2
rename ds variable in epilogue to a longer name 2018-11-15 15:04:02 +01:00
Houtan Bastani a8c7fb694b
fix typo 2018-11-15 14:48:31 +01:00
Houtan Bastani 987465365c
Revert "macroprocessor: allow inline comments. closes #1550"
This reverts commit 17dd443341.
2018-11-15 12:34:05 +01:00
Houtan Bastani eca82834a1
Revert "Fix parsing of empty strings in macro-processor"
This reverts commit 158f027db2.
2018-11-15 12:33:59 +01:00
Houtan Bastani 8e1cb261c5
Revert "only allow inline comments on statement lines. #4"
This reverts commit 3776e3b890.
2018-11-15 12:24:40 +01:00
Houtan Bastani 989532a6a2
add `string`, vec_str key/value option to posterior_sampler_options 2018-11-09 15:11:15 +01:00
Sébastien Villemot e22aa1c162
Compatibility issue with Bison 3.2 2018-11-08 15:01:43 +01:00
Houtan Bastani 5f5fd569dd
add onlymodel command line option 2018-11-07 15:35:03 +01:00
Sébastien Villemot beb99d98cd
Build system improvements for MSYS2
On Windows/MinGW, use the -static linking flag. This enforces static linking of
Boost libraries, which is needed on MSYS2.

Also, use AM_CXXFLAGS and AM_LDFLAGS variables for changing flags, since
CXXFLAGS and LDFLAGS are user variables.
2018-11-06 12:14:49 +01:00
Sébastien Villemot f223af91af
Improve the fix in 366701c094
Now both x+(-y) and (-x)+y are simplified using a minus operator.

Also simplify some code using std::swap().
2018-11-05 12:31:12 +01:00
Sébastien Villemot 366701c094
Apply x+(-y) ⇒ x-y simplification even when x and y are permuted
Incidentally, this fixes an issue in DataTree::operator=(), where this would
cause to the copy to have a different number of nodes than the original.
2018-11-05 11:28:00 +01:00
Sébastien Villemot ee5fc6b16b
Simplify parsing of options using C++ strings 2018-10-31 11:17:26 +01:00
Houtan Bastani 08caaa0744
backslashes not used in escape sequences are not allowed in strings in Julia v1.0
See: https://github.com/JuliaLang/julia/issues/21284
2018-10-30 12:14:26 +01:00
Sébastien Villemot b337a5aec0
Fix usage 2018-10-29 14:55:02 +01:00
Sébastien Villemot 4a974bb428
The preprocessor now compiles the MEX when use_dll is specified
New options "mexext" and "matlabroot" are introduced, so that the preprocessor
knows where to find MATLAB and which architecture to compile for.

Only recent gcc is now supported. A set of optimization flags is used so that
compilation goes reasonably fast on large models.

Consequently, options "msvc", "mingw" and "cygwin" have been removed.
2018-10-26 18:09:13 +02:00
Sébastien Villemot 1c33af4844
Fix bug introduced in bfd93f4ac0 with correlations in estim_params
For correlations, there is one extra columns (since there are two symbol
indices). MATLAB automatically adds the missing column, while Octave is
stricter when verifying dimensions.

By the way, add a missing comma.
2018-10-26 11:11:10 +02:00
Stéphane Adjemia (Scylla) bfd93f4ac0
Fixed estimated_params_init behaviour...
... when an initial value is given to a parameter that is not
estimated.

The generated driver file was crashing with cryptic error message
because we were searching in the first (and second) column of a
potentially empty array with 0 columns. The fix is to initialize the
fields of estimated_params_ with empty arrays with 10 columns (ie
zeros(0, 10)). Also print a message in the matlab command window if
parameter declared in estimated_params_init is not estimated.
2018-10-25 10:24:25 +02:00
Houtan Bastani bef7c2a193 remove need to declare equations nonstationary 2018-10-24 16:04:51 +02:00
Houtan Bastani 9968f5c971 fix bug in JSON output: JSON values that are decimals must be preceded by a 0
e.g. 0.5 is valid but .5 is not.
2018-10-23 14:00:36 +02:00
Houtan Bastani 9eaf39235e write aux_unary_op function to output 2018-10-15 12:04:53 +02:00
Houtan Bastani 55b625b016 undiff expansion of var_expectation 2018-10-12 15:21:03 +02:00
Sébastien Villemot 1089a223c4 Clean up default constructors/destructors 2018-10-11 17:08:44 +02:00
Sébastien Villemot ac94ad906e Various fixes for silencing errors and warnings under Clang 6 2018-10-11 11:21:58 +02:00
Sébastien Villemot bcdfb43fd3 Replate DynamicModel::toStatic() by a converting constructor in StaticModel
It is therefore now possible to write:

  static_model = static_cast<StaticModel>(dynamic_model);
2018-10-10 17:08:54 +02:00
Sébastien Villemot 0e7d831e6f Remove redundant private keyword 2018-10-10 17:08:10 +02:00
Sébastien Villemot 52ce0d8ba9 Fix bug with discretionary_policy
Since, in this case, there are less equations than endogenous, the
variable_reordered structure was not filled with enough element, leading to an
invalid memory read when printing M_.state_var.

Ref #637
2018-10-10 17:08:01 +02:00
Sébastien Villemot 63a5ffb761 Rename ExprNode::cloneDynamic into ExprNode::clone, for clarity 2018-10-10 13:08:11 +02:00
Sébastien Villemot 24f1276b42 Make all DataTree::*_map private
Introducing a new DataTree::getVariable() const method was necessary in the process.
2018-10-10 13:03:52 +02:00
Sébastien Villemot f2cf86b734 Add copy constructors / assignment operators for the DataTree class hierarchy
In particular, it is necessary to turn back DataTree::AddVariable() into a
non-virtual method, because it is called from DataTree's constructor. Enforcing
the absence of leads/lags is now done using a new boolean DataTree::is_static.

Take advantage of the new copy constructor for handling
PlannerObjectiveStatement more elegantly.

Unfortunately it is not possible to implement *move* constructor / assigment
operators, because the reference ExprNode::datatree is not mutable.
2018-10-10 12:53:55 +02:00
Sébastien Villemot 215283005e No longer store symbol type in VariableNode
This facilitates switching variable types on the fly. In particular, this
allows removing the hack in DynamicModel::updateAfterVariableChange() that way
basically recreating all the nodes after the type change.
2018-10-10 12:34:05 +02:00
Sébastien Villemot c47b6e6e4c Fix bug with notmpterms option
Commit c6cb9aa1b8 was not the right fix.
2018-10-05 17:14:27 +02:00
Sébastien Villemot 9043efab32 Replace "class" by "typename" in template declarations 2018-10-04 18:08:19 +02:00
Sébastien Villemot 6d26dc2349 Remove implicitly-defined copy/move constructors/assignments in several classes 2018-10-04 18:08:17 +02:00
Sébastien Villemot 7bb5382428 Always use brace-initializer in constructors
The syntax makes clearer the distinction between a function call and an
initialization. Also, it prevents bugs due to implicit type conversions.
2018-10-04 17:19:18 +02:00
Sébastien Villemot a4aefb4c65 Mark all constructors taking a single argument as "explicit"
For a rationale, see http://www.sjbrown.co.uk/2004/05/01/always-use-explicit/
2018-10-04 17:19:18 +02:00
Stéphane Adjemian (Charybdis) ec872e63fd
Cosmetic change. 2018-10-04 16:54:57 +02:00
Sébastien Villemot 38f13eb0ad Remove nonsensical check on MS Visual C++ version
The check is done at the time the preprocessor is compiled, but it ought to be
done at the time when the C source file generated by the preprocessor is compiled…

Anyways, it is probably irrelevant now, since MSVC has supported
acosh/asinh/atanh for a long time now.
2018-10-02 18:23:39 +02:00
Sébastien Villemot 48940ff899 Convert SvarRestrictionType into a class enum 2018-10-02 18:15:31 +02:00
Sébastien Villemot 3f26933f44 Replace ExternalFunctionSetOrNot enum by integer constants
This was not conceptually an enum, but rather a collection of unrelated
constants:
- two constants for use as placeholder for symbol IDs at different places
- one constant for the default number of arguments
2018-10-02 18:10:12 +02:00
Sébastien Villemot 5e6b8f0a6b No longer test for __MINGW32__ macro, testing for _WIN32 is enough
Closes: Dynare/dynare#1315
2018-10-02 16:50:07 +02:00
Sébastien Villemot 15d026e54e C output: split generated function into several smaller subfunctions
This mimicks the structure of M-functions (though the logic for filling the
temporary terms vector is a bit different).

This change implied a modification in the way we compute the checksum in case
of block decomposition (the temporary terms for the C output are not correctly
computed in that case).
2018-10-01 16:04:01 +02:00
Sébastien Villemot 42e31ad6e1 Ensure that linear_decomposition is false by default 2018-10-01 10:52:19 +02:00
Ferhat Mihoubi 139e3efa82 Adds a new model option "linear_decomposition" that creates a block composed of the non-linear equations o the model 2018-09-28 14:54:52 +02:00
Michel Juillard 680fb72d0d allowing for different number of periods in conditional_forecast_path 2018-09-27 15:19:30 +02:00
Houtan Bastani 63a334cfd3 fix typo 2018-09-27 10:47:13 +02:00
Sébastien Villemot c6cb9aa1b8 Fix bug in option notmpterms with model local variables
Since model local variables are now treated as temporary terms, they must be
marked as such even when option notmpterms is present.
2018-09-25 15:57:56 +02:00
Houtan Bastani fbeae9619a aesthetic fix 2018-09-25 15:48:05 +02:00
Houtan Bastani 7282b7bf32 fix bug in filling of var AR matrix 2018-09-25 15:47:52 +02:00
Houtan Bastani 6c7d7f5d44 don’t create file if trend_component_model/var_model statement not present 2018-09-25 12:18:52 +02:00
Sébastien Villemot 913bc2f8c2 Macro-processor, comprehension: fix error message, add comments 2018-09-24 18:17:28 +02:00
Sébastien Villemot 3e5c8dd80d Macro-processor: implement comprehensions
Due to a limitation of the current implementation, this breaks syntaxes like
[ (i,j) ] (but not [ (2,j) ]; the problem only occurs when an array is
constructed by specifying as first element a tuple whose first element is a
variable name). Solving this problem requires an overhaul of the
macro-processor, with construction of ASTs at parsing time, and evaluation
later on (instead of doing on-the-fly evaluation).

Ref #5
2018-09-24 18:00:59 +02:00
Sébastien Villemot 7a5cc7e54b Minor fixes to comments 2018-09-18 19:12:25 +02:00
Houtan Bastani c9f5cef99b write AST in JSON 2018-09-18 17:48:04 +02:00
Houtan Bastani 8ec06dddc4 fix typo and remove unnecessary braces 2018-09-18 17:31:51 +02:00
Houtan Bastani 9f9c8fdfbf fix typo 2018-09-18 14:50:54 +02:00
Houtan Bastani 85dbb649b7 move trend_component_table and var_model_table to DynamicModel as they are only used there 2018-09-14 17:04:06 +02:00
Houtan Bastani eb74d48393 trend_component_model: replace `trends` option with `targets` 2018-09-13 12:21:23 +02:00
Houtan Bastani dfb0629c25 fix typo 2018-09-12 18:21:34 +02:00
Houtan Bastani dc9ecbb49a fix bug in columns of EC matrix 2018-09-12 17:56:30 +02:00
Houtan Bastani 0376f7f173 fix bugs in creation of AR/EC matrices 2018-09-12 11:57:14 +02:00
Houtan Bastani aa120abd02 simplify code 2018-09-12 11:57:14 +02:00
Houtan Bastani 8acee8fd54 fix AR and EC matrices for double diff 2018-09-11 16:56:05 +02:00
Houtan Bastani f71c861d5e output EC matrix in file for trend component models 2018-09-10 17:44:04 +02:00
Houtan Bastani 46709ada3f output AR matrix in file for trend component models 2018-09-10 14:51:33 +02:00
Houtan Bastani f5e5dea1be support hard-coded parameters and parameter expressions in AR matrix 2018-09-07 10:14:18 +02:00
Houtan Bastani acc197f539 output AR matrix in file 2018-09-06 18:00:05 +02:00
Sébastien Villemot e19a14869e Convert ExprNodeOutputType into a class enum
Incidentally, replace the IS_* macros by inline functions.
2018-09-05 18:28:32 +02:00
Sébastien Villemot c6d4cb88c3 ExprNode and its subclasses are no longer friends of DataTree
This ensures a better isolation between the container and the containees.
2018-09-05 18:28:32 +02:00
Sébastien Villemot 004d909621 Use smart pointers for storage of ExprNode in DataTree class
- BTW, store them in a std::vector rather than std::list

- incidentally, fix issue in VariableNode::removeTrendLeadLag where expression
  sharing was possibly violated when creating a new VariableNode
2018-09-05 18:28:32 +02:00
Sébastien Villemot 5d2e1cf7b9 Use smart pointers for storage of Statement in ModFile class 2018-09-05 18:28:27 +02:00
Houtan Bastani 9f0c30740e introduce epilogue block 2018-09-05 12:31:49 +02:00
Sébastien Villemot e3550a8fc0 Various fixes in comments 2018-09-04 17:28:47 +02:00
Sébastien Villemot 3fd6858fb8 Macroprocessor: fix priority of operators
- == and != have now lower priority than <= < >= >, for consistency with the
  Dynare modelling language (and incidentally C and C++, but not Julia).

- ^ has now higher priority and no associativity, for consistency with the
  Dynare modelling language (and usual arithmetic notation).

- & has now higher priority than |, and both have lower priority than + and -,
  but higher than inequality comparators. This is not the same as C and C++ (in
  which & and | are just above && and ||), but this allows for expressions such
  as "a|b == c" to have their most natural semantics (i.e. this will compare
  the union of a and b with c; the C/C++ priority level would have resulted in
  a type error).

Ref #5.
2018-09-04 17:09:11 +02:00
Sébastien Villemot 4624a3104d Macroprocessor: implement power operator for integers
For consistency with the power operator for sets (see #5).
2018-09-04 16:28:38 +02:00
Stéphane Adjemian(Charybdis) a35c1785a8 Cosmetic change. 2018-09-04 12:08:05 +02:00
Houtan Bastani 49d8931fc0 fix typo in 8584323563 2018-09-04 10:45:39 +02:00
Houtan Bastani 8584323563 provide information on order of ec.vars 2018-09-04 10:39:05 +02:00
Houtan Bastani d89d6cc685 bug fix: close opened steady state file 2018-09-04 09:41:12 +02:00
Houtan Bastani 27c9a9a5e0 store LHS of trend equation in trend_vars 2018-09-03 17:25:42 +02:00
Houtan Bastani 7a438a3ce7 ensure that trend_variable found is actually a trend variable as declared in the trend_component_model statement 2018-09-03 15:05:30 +02:00
Houtan Bastani fde836d7fe trend_component_model: find trend_vars associated with equation 2018-08-31 14:24:44 +02:00
Houtan Bastani 52da3ecfa7 fix bug: missing initialization for lexer context variable 2018-08-29 18:02:12 +02:00
Houtan Bastani 95da532275 remove incorrect option as `unput` is used in flex file 2018-08-29 12:55:17 +02:00
Houtan Bastani 948e8cb6e4 fix bug in creation of ec vars for pac equation 2018-08-28 16:00:25 +02:00
Houtan Bastani 9e6bdc2334 Revert "fix bug in collection of ec vars of pac equation"
This reverts commit 74dd6a69e9.
2018-08-28 13:32:48 +02:00
Houtan Bastani 74dd6a69e9 fix bug in collection of ec vars of pac equation 2018-08-27 16:41:39 +02:00
Houtan Bastani 1ae729929b fix bug when var_expectation_model uses trend_component_model as auxiliary model 2018-08-27 14:51:54 +02:00
Houtan Bastani d5d6e8beb0 simplify updating of RHS variables for trend component and var models 2018-08-23 13:57:27 +02:00
Houtan Bastani 16f10d954f don’t rely on scope: clean up iterator names 2018-08-23 13:03:52 +02:00
Houtan Bastani 97af0ff711 fix bug in updating variables in var model table 2018-08-23 10:28:19 +02:00
Houtan Bastani 0c66e724cb fix typo 2018-08-22 17:09:16 +02:00
Houtan Bastani 54df07d0e0 remove unnecessary comment 2018-08-22 17:01:03 +02:00
Houtan Bastani 7d9072a227 var_expectation: rename var_model_name to aux_model_name 2018-08-22 16:57:36 +02:00
Stéphane Adjemia (Scylla) a406c18598 Allow trend_component_model in var_expectations. 2018-08-22 16:50:01 +02:00
Houtan Bastani 1874fa5cce remove unused variable 2018-08-22 16:01:10 +02:00
Houtan Bastani 80c45ee116 fix bug with max_lag of var model 2018-08-22 15:59:12 +02:00
Houtan Bastani 0af91c26f8 aesthetic fix 2018-08-22 15:12:17 +02:00
Houtan Bastani 91b7888e61 print nonstationary field for trend_component and var models 2018-08-22 14:29:07 +02:00
Houtan Bastani 1918a56a70 fix bug in 539fddc9f6 2018-08-22 12:56:16 +02:00
Houtan Bastani 539fddc9f6 introduce var model table 2018-08-22 12:15:02 +02:00
Houtan Bastani 6015b0e57b fixes to trend component model 2018-08-22 12:15:02 +02:00
Houtan Bastani 0d5dd11106 fix typo 2018-08-20 10:50:28 +02:00
Houtan Bastani afe0e475b1 trend_component_model statement 2018-08-17 16:52:48 +02:00
Houtan Bastani 618147a126 fix typo 2018-08-16 11:09:54 +02:00
Stéphane Adjemian(Charybdis) 74b693a1ec Cosmetic change. 2018-08-14 16:46:43 +02:00
Stéphane Adjemian(Charybdis) adbeb49b29 Do not print non optimizing behaviour field in PAC if empty. 2018-08-14 16:45:01 +02:00
Houtan Bastani ac850f5187 pac: stop processing of PAC equation if optimizing share parameter is hard-coded 2018-08-13 17:22:28 +02:00
Houtan Bastani d3bd6ace90 pac: print optimizing share parameter 2018-08-13 17:00:47 +02:00
Houtan Bastani edc242d471 preprocessor: find optimizing shares of agents in PAC equation 2018-08-13 14:34:57 +02:00
Houtan Bastani c5c61f99ba fix bug with max_lag reported for PAC equation 2018-08-13 12:12:20 +02:00
Houtan Bastani 0dffee4650 fix typo 2018-08-13 11:08:58 +02:00
Houtan Bastani d657f77149 fix typo :) 2018-08-09 13:27:05 +02:00
Houtan Bastani 719630a53c macroprocessor: allow looping over tuples. #5 2018-08-08 17:23:33 +02:00
Houtan Bastani ca066ea398 macroprocessor: introduce shortcut for Cartesion product (^). #5 2018-08-08 15:58:49 +02:00
Houtan Bastani d9c0568075 macroprocessor: introduce Cartesion product. #5 2018-08-08 15:11:06 +02:00
Houtan Bastani e24cabe3a5 var_expectation: print type specific id for discount index 2018-08-08 14:59:50 +02:00
Houtan Bastani 27d088da7e macroprocessor: fix bug in set difference introduced in 5f1465f9 2018-08-08 14:35:09 +02:00
Houtan Bastani 428b5023d3 macroprocessor: intersection operator. #5 2018-08-08 14:15:39 +02:00
Houtan Bastani 039b27bbaf macroprocessor: union operator. #5 2018-08-08 14:12:04 +02:00
Houtan Bastani 1285473aa1 macroprocessor: introduce tuple type. #5 2018-08-07 17:36:13 +02:00
Houtan Bastani 88a0162202 macroprocessor: remove terminals not used in grammar 2018-08-07 17:19:45 +02:00
Stéphane Adjemian(Charybdis) b20da7c43f Fixed timing issue in VAR_EXPECTATION expansion. 2018-08-06 21:36:52 +02:00
Stéphane Adjemian(Charybdis) 32da131a77 Added associated index in M_.endo_names for expected variable. 2018-08-04 19:50:12 +02:00
Stéphane Adjemian(Charybdis) ed32caeb46 Added missing field in VAR_EXPECTATION_MODEL description (variable). 2018-08-04 12:03:53 +02:00
Stéphane Adjemian(Charybdis) 022395aaf6 Fixed param_indices vector for VAR_EXPECTATION_MODEL. 2018-08-04 11:46:31 +02:00
Sébastien Villemot f3c2a1bf87 New var_expectation_model statement and re-design of var_expectation operator
Given a previously declared var_model, the var_expectation_model statement is
used to declare a way of forming expectations with this VAR (possibly using a
finite or infinite discounted sum). The var_expectation operator now takes a
single argument, the name of the var_expectation_model.

For the moment, this only works when the var_model is using equations
explicitly declared in the model block.
2018-08-02 08:39:09 +02:00
Sébastien Villemot 8a03532c78 ParsingDriver: factorize code to check symbol types 2018-08-01 10:47:56 +02:00
Sébastien Villemot 122e154764 PlannerObjectiveStatement now owns its model_tree
By the way, error out if the planner_objective statement is used two times.
2018-07-31 13:00:41 +02:00
Sébastien Villemot 0a063eecc1 More smart pointers 2018-07-31 13:00:39 +02:00
Sébastien Villemot 66a712253a Macroprocessor: cosmetic change 2018-07-31 12:02:26 +02:00
Sébastien Villemot df01e52859 Use new syntax for various Bison options 2018-07-31 12:02:26 +02:00
Sébastien Villemot 4302307f7d Force Emacs to use C++ mode when opening Bison and Flex files 2018-07-31 12:02:24 +02:00
Sébastien Villemot 7280c92642 Use variant semantic values in the Bison parser
We can therefore manipulate objects by value rather than by pointers, which
saves a lot of memory manipulations (and avoid potential segfaults and memory
leaks).

Note that there is no default action ("$$ = $1") when using the variant type,
so we add them explicitly.
2018-07-31 11:48:08 +02:00
Sébastien Villemot 725b91e5d6 Several fixes to computing tasks statements
- store objects whose persistence is not guaranteed (e.g. strings) as values
  instead of references (to avoid possible segfaults)
- on the contrary, always store the SymbolTable as a reference, since its
  persistence is guaranteed, and we don't want to copy it
- use pass-by-value in constructors whenever possible
- remove useless const keyword when passing by value
2018-07-31 10:51:28 +02:00
Sébastien Villemot 107ad1432b Fix various Bison warnings 2018-07-30 19:38:46 +02:00
Sébastien Villemot 45cd8e6853 Fix regression in nested diffs introduced in 90d8b579
See McModelTeam/McModelProject/issues/97.
2018-07-30 12:53:23 +02:00
Sébastien Villemot b9ee0bb204 aux_equations may diverge from those in the main model
aux_equations only contain the definition of auxiliary variables, and
may diverge from those in the main model (equations), if other model
transformations applied subsequently. This is not a problem, since
aux_equations is only used for regenerating the values of auxiliaries
given the others.

For example, such a divergence appears when there is an expectation
operator in a ramsey model, see
tests/optimal_policy/nk_ramsey_expectation.mod */
2018-07-27 14:20:36 +02:00
Sébastien Villemot 762f25abe9 Remove useless separate list for diff auxiliary variables
This table serves no useful purpose. It is better to append auxiliary equations
at the time they are created, to avoid messing with the recursive ordering.
2018-07-26 17:41:58 +02:00
Sébastien Villemot 90d8b579cc Fix incorrect recursive ordering of aux vars with diff not used at current period
Ensure that all diff operators appear once with their argument at current
period (i.e. maxLag=0).
If it is not the case, generate the corresponding expressions.

This is necessary to avoid lags of more than one in the auxiliary
equation, which would then be modified by subsequent transformations
(removing lags > 1), which in turn would break the recursive ordering
of auxiliary equations.

See McModelTeam/McModelProject/issues/95 for an example.
2018-07-26 17:41:58 +02:00
Sébastien Villemot 9cf3e034de Macroprocessor: allow empty arrays
This is now easy to implement, thanks to the refactoring allowing any type of
objects in arrays.

Closes DynareTeam/dynare#707
2018-07-25 18:46:55 +02:00
Sébastien Villemot 88fab669c6 Macroprocessor: length() operator called on a string returns the number of characters
Closes DynareTeam/Dynare#1547
2018-07-25 18:42:23 +02:00
Sébastien Villemot 5f1465f9d1 Macroprocessor: replace naked pointers by smart pointers
- use std::unique_ptr for MacroDriver::lexer
- use std::shared_ptr for MacroValue objects constructed by the parser
  This is made possible using Bison 3.0 variant value type.
  Using non-pointer type is not possible since MacroValue is polymorphic.
  Using std::unique_ptr is not possible since the value type must be
  copyable (see
  https://lists.gnu.org/archive/html/bug-bison/2015-03/msg00004.html).
  Define a new type MacroValuePtr == shared_ptr<const MacroValue> for code
  clarity.
  Use the following convention for shared_ptr arguments to functions:
  + if pass-by-value, means that the callee acquires ownership
  + if pass-by-const-reference, the callee does not acquire ownership
- naked pointers are still used for tracking the filename in Bison's location
  type, since we don't have control over that

Also, by the way:
- arrays can now contain elements of any type
- simplify MacroDriver::loop_stack using std::tuple
- toArray() method now fails on function objects
- no need to use const qualifiers, since all MacroValue objects are immutable
- use an exception for detecting division by zero
2018-07-25 18:40:23 +02:00
Sébastien Villemot 372005ed27 Bison: use the %language directive instead of %skeleton for specifying C++ 2018-07-24 14:02:10 +02:00
Sébastien Villemot 937659747a Macroprocessor: error out when length() operator called on a string or an int
Closes DynareTeam/Dynare#1547
2018-07-24 12:49:08 +02:00
Stéphane Adjemian(Charybdis) 49e1c43aed Partially reverted 19048bdca.
There is no reason to associate an exogenous variable or parameter to a
specific equation. For these types the user can use the pipe
notation (|x, |p) in any equations or the usual parameters and varexo statements.
2018-07-19 23:29:27 +02:00
Sébastien Villemot 4a04a38374 C++11: convert ExtendedPreprocessorTypes to class enums 2018-07-18 17:28:26 +02:00
Sébastien Villemot 97868cbd2a Remove unneeded enum keyword 2018-07-18 17:28:26 +02:00
Sébastien Villemot 04b6690d5a C++11: convert ExternalFunctionType to a class enum 2018-07-18 17:28:23 +02:00
Sébastien Villemot 14948401e4 C++11: convert PriorDistributions to a class enum 2018-07-18 16:52:12 +02:00
Sébastien Villemot edddc9d8ca C++11: convert NodeTreeReference to a class enum 2018-07-18 16:35:19 +02:00
Sébastien Villemot 4ad0e500d4 C++11: convert {Unary,Binary,Trinary}Opcode to class enums 2018-07-18 16:18:26 +02:00
Sébastien Villemot 11b1fdcffd Fix implicit narrowing conversions (omitted in previous commit) 2018-07-18 15:12:00 +02:00
Sébastien Villemot d6055c1407 C++11: convert SymbolType to a class enum 2018-07-17 18:55:26 +02:00
Sébastien Villemot c12088f314 C++11: convert AuxVarType to class enum 2018-07-17 17:38:26 +02:00
Sébastien Villemot 89832db1db C++11: convert MatrixForm to a class enum 2018-07-17 17:31:20 +02:00
Sébastien Villemot 946d105c04 Remove C and C++ preprocessor output types
This code is broken since the temporary terms array changes. It is probably not
worth maintaining it.
2018-07-17 16:52:11 +02:00
Sébastien Villemot b8a5dfdc39 Replace several usages of C macroprocessor with C++ constructs 2018-07-17 16:36:58 +02:00
Houtan Bastani 8cf4fedac2 macroprocessor: change type of function arguments 2018-07-11 15:57:51 +02:00
Houtan Bastani 3776e3b890 only allow inline comments on statement lines. #4 2018-07-11 14:31:58 +02:00
Houtan Bastani aea9011745 Revert "macroprocessor: don’t interpret inline comments yet put them to output (ignored by dynare preprocessor, but printed in macro expanded file). #4"
This reverts commit 27e6d92af1.
2018-07-11 12:15:58 +02:00
Houtan Bastani 357320468b Revert "macroprocessor: support Matlab comments. #4"
This reverts commit 066942ef22.
2018-07-11 11:37:58 +02:00
Houtan Bastani a2fef7804e Revert "macroprocessor: support multi-line comments. #4"
This reverts commit 86a08f54ae.
2018-07-11 11:37:40 +02:00
Houtan Bastani 15f5f4f1be use front inserter instead of back inserter for unary/diff auxiliary equations
(cherry picked from commit 6a95831147d942c23fbc3a0a0b1506650eb49b7d)
2018-07-10 12:06:42 +02:00
Sébastien Villemot 7baee73126 Fix bug under MATLAB+Windows when "+" subdirectory is already present
Under MATLAB+Windows (but not under Octave nor under GNU/Linux or macOS), if we
directly remove the "+" subdirectory, then the preprocessor is not able to
recreate it afterwards (presumably because MATLAB maintains some sort of lock
on it). The workaround is to rename it before deleting it.
2018-07-09 18:18:26 +02:00
Houtan Bastani 86a08f54ae macroprocessor: support multi-line comments. #4 2018-07-09 16:55:59 +02:00
Houtan Bastani 066942ef22 macroprocessor: support Matlab comments. #4 2018-07-09 16:55:53 +02:00
Houtan Bastani 27e6d92af1 macroprocessor: don’t interpret inline comments yet put them to output (ignored by dynare preprocessor, but printed in macro expanded file). #4 2018-07-09 16:55:38 +02:00
Houtan Bastani e0bf2b60b6 Modify 19048bdcae to store equation tags for variables declared in equation tags 2018-07-09 14:49:12 +02:00
Houtan Bastani 19048bdcae Allow for the declaration of endogenous, exogenous, parameters on-the-fly in equation tags 2018-07-09 14:39:13 +02:00
Houtan Bastani a7f8eaa336 remove warnings introduced in 244552393b 2018-07-09 11:55:39 +02:00
Houtan Bastani 853cce553f replace ‘typedef’ with ‘using’ 2018-07-09 11:49:17 +02:00
Houtan Bastani 244552393b macroprocessor: add support for functions that return strings. #3 2018-07-04 17:04:22 +02:00
Houtan Bastani a51dd224e4 simplify conversion of int to string 2018-07-04 16:07:16 +02:00
Sébastien Villemot 543e2b16e3 Simplify and modernize ConfigFile
- no longer use pointers
- use pass-by-value when possible
- use range-for loops when possible
2018-07-04 15:56:48 +02:00
Sébastien Villemot 53f83aeb12 No longer use boost::lexical_cast
Most cases can be handled in C++11 by std::stoi() and std::stod().

For the macroprocessor ArrayMV<T>::print() method, use template
specialization (instead of a lexical_cast to detect between T=int and
T=string).
2018-07-04 15:53:41 +02:00
Sébastien Villemot 30c205f418 C++11: replace calls to std::atof() by std::stod() 2018-07-04 14:53:13 +02:00
Sébastien Villemot 5e1d722013 C++11: replace most calls to std::atoi() by std::stoi()
The latter accepts a std::string as argument.
2018-07-04 14:53:08 +02:00
Sébastien Villemot e376267a28 Move json generated files to ${MODFILE}/model/json/ 2018-06-27 16:08:31 +02:00
Sébastien Villemot 988a9f6e2d std::open and std::fstream constructor accept a std::string for filename in C++11 2018-06-27 15:30:45 +02:00
Sébastien Villemot b91ed6f78c Move the location of static and dynamic files on the filesystem
- M and MEX files are now under +${MODELNAME}/
- bytecode and C source now under ${MODELNAME}/model/
2018-06-27 15:30:25 +02:00
Houtan Bastani 45f7e40a88 remove unused library 2018-06-27 13:50:15 +02:00
Houtan Bastani bbb2b067bf prevent compilation warning 2018-06-27 13:45:51 +02:00
Stéphane Adjemian(Charybdis) a2b19cbfff Added missing writeJsonOutput method for VarModelStatement. 2018-06-15 14:56:44 +02:00
Sébastien Villemot 158f027db2 Fix parsing of empty strings in macro-processor
Those were treated as comments.

Incidentally, fix a similar issue in the Dynare parser (which is much less
problematic, since double quotes are not used in the Dynare language).

Closes DynareTeam/dynare#1621
2018-06-14 16:54:31 +02:00
Houtan Bastani b8ae9f6935 Fix max lags for var 2018-06-11 15:18:06 +02:00
Houtan Bastani 84c2dc5f36 transform_unary_ops now introduces aux variables/equations for all unary ops specified by UnaryOpNode::createAuxVarForUnaryOpNode()
In the absence of this option, if a var_model statement(s) is present, then aux vars/eqs are created for the same types of unary operators but only for equations specified in the var_model statement

In the absence of both this option and var_model statements, no unary op auxiliary variables are created

diffs continue to be substituted everywhere; for the moment auxiliary variables are created for diffs of expressions. A forthcoming change will allow auxiliary variables created for diffs of expressions to be linked with their lagged expressions as is currently the case for diffs of variables
2018-06-07 17:16:12 +02:00
Houtan Bastani a30f8f365e Only create auxiliary variables for diffs that appear in VAR equations or equations that have pac_expectations in them
Otherwise, substitute the diff (i.e. `diff(x)` -> `x-x(-1)`)
2018-06-05 18:39:13 +02:00
Houtan Bastani 27320a07f6 update statement loops to use C++11 syntax 2018-06-05 18:39:13 +02:00
Houtan Bastani 2cd3aa95cc When `transform_unary_ops` is passed, only substitute unary operators that appear in VAR equations 2018-06-05 17:41:15 +02:00
Sébastien Villemot 130004ef47 Simplify types for storing derivatives using std::tuple 2018-06-05 15:34:34 +02:00
Sébastien Villemot 52d8bd0b17 Stop using namespace boost globally in ModelTree
Otherwise boost::tuple overrides std::tuple.
2018-06-05 15:33:46 +02:00
Houtan Bastani 4d92baaf29 Clean up writing of equation tags in latex file 2018-06-05 14:47:36 +02:00