Commit Graph

76 Commits (master)

Author SHA1 Message Date
Sébastien Villemot d635aac04a
Turn some loop variables into const references when possible
Automatically detected by clang-tidy using performance-for-range-copy check.
2023-12-13 14:21:09 +01:00
Sébastien Villemot d463607e90
Reformat C++ source code using clang-format 15 2023-11-30 15:58:32 +01:00
Sébastien Villemot f179ec4dac
Use __builtin_unreachable() to silent some GCC warnings
This is cleaner than using exit() or assert() for that purpose.
2023-10-18 14:28:59 -04:00
Sébastien Villemot 62c455ff56
Misc simplifications using STL algorithms 2023-02-28 16:27:29 +01:00
Sébastien Villemot 0bc1539f45
Drop clang workaround 2023-01-05 18:11:33 +01:00
Sébastien Villemot 93054cf692
Various filesystem refactorings
– DataTree::packageDir() now takes a std::string_view, returns a
  std::filesystem::path, and no longer creates that directory
– DataTree::writeToFileIfModified() now takes a std::filesystem::path as
  argument
– Do not call DataTree::writeToFileIfModified() for generating MATLAB/Octave
  files, since it does not work (the directory inside which the file is written
  has been deleted by the preprocessor just before)
– Consistently use DataTree::packageDir() everywhere (for compatibility with
  planner_objective)
2022-10-11 16:28:17 +02:00
Sébastien Villemot 3d9ac26aa6
Remove all instances of the “map.find(key)->second” pattern
This is unsafe since the find() method can return a past-the-end iterator,
which should be tested for.

Replace most instances by calls to the std::map::at() method (which throws if
the key is unknown), and which is incidentally more readable.
2022-09-27 12:56:16 +02:00
Sébastien Villemot c8b046ec86
Simplification using non-default std::ofstream constructor 2022-07-11 22:17:36 +02:00
Sébastien Villemot 3b99ac5df0
Remove unused parameters to various methods 2022-06-24 17:11:38 +02:00
Sébastien Villemot c94dfb848c
C++20 modernization: use initialization within range-based for loop
In particular, use this feature in many loops which feature a special treatment
for the first iteration, using a boolean variable (replacing iterator
manipulation). By the way, also use std::exchange() to simultaneously test the
value of this variable and update it.
2022-06-07 14:35:59 +02:00
Sébastien Villemot 0b5c88109f
Various simplifications 2022-06-07 14:34:30 +02:00
Sébastien Villemot 3e94250582
C++17 modernization: use std::optional in ExprNode::getPacOptimizingShareAndExprNodes() 2022-05-16 19:10:16 +02:00
Sébastien Villemot 0eb11d3323
C++17 modernization: use std::optional in expression matching functions 2022-05-16 19:10:16 +02:00
Sébastien Villemot 3496d77eb4
C++17 modernization: use std::optional to store orig diff vars in VAR and TCM
By the way, remove the unused TrendComponentModelTable::getOrigDiffVar() method.
2022-05-16 19:10:16 +02:00
Sébastien Villemot fc037a4352
Simplify printing of booleans using std::boolalpha 2022-05-16 19:10:15 +02:00
Sébastien Villemot 92d3b8166a
C++17 modernization: use std::optional for equation line numbers 2022-05-16 19:10:15 +02:00
Sébastien Villemot 0b51294994
C++17 modernization: use std::optional for trend variables in TCM 2022-05-16 19:10:15 +02:00
Sébastien Villemot 46a85644d8
C++20 modernization: update comment about workaround for clang 2022-05-04 17:37:58 +02:00
Sébastien Villemot b42ee40b55
C++20 modernization: use contains() method on containers 2022-05-04 17:37:57 +02:00
Sébastien Villemot c03f4a559a
Fix JSON output when there are multiple “var_expectation_model” statements
Ref. Madysson/estimation-codes#19
2022-02-15 20:58:36 +01:00
Sébastien Villemot 01bea3f5e7
TCM: remove useless 3rd dimension of A0 and A0star (supposedly for lags) 2022-01-28 16:38:50 +01:00
Sébastien Villemot 1e77f7c5a7
SymbolTable::getOrigSymbIdForAuxVar() now also works on unaryOp and diffForward auxvars
This is a more natural semantics.

Incidentally, this fixes a bug in the variable mapping (M_.mapping) where some
endogenous, appearing in a log() in a VAR or TCM, would not be mentioned (e.g.
in the var-expectations/7/example1.mod test, and many others).
2022-01-28 16:30:11 +01:00
Sébastien Villemot 6936e54d42
Remove unused field M_.pac.(model_name).lhs
It contains symbol IDs, so it cannot be used from MATLAB/Octave code.
2022-01-25 10:34:46 +01:00
Sébastien Villemot 49fa876444
Add missing “time_shift” option to JSON output of var_expectation_model 2022-01-20 16:26:17 +01:00
Sébastien Villemot aa0e06bc7d
Refactor handling of var_expectation_model statements
Creates a VarExpectationModelTable analogous to PacModelTable.
2022-01-20 16:26:15 +01:00
Sébastien Villemot d149d3a76c
PAC: substitute unary ops in “growth” expressions (in “pac_model” and “pac_target_info”)
Ref. dynare#1837
2022-01-18 12:40:15 +01:00
Sébastien Villemot f05b552f31
PAC: correctly handle log() and diff() operators in the equation defining the target
By default, the preprocessor substitutes logs and diffs by auxiliary variables
only in equations of auxiliary models (VAR, PAC). Hence they are not
substituted in the equation defining the target, since it is outside the
auxiliary model.

The fix consists in doing the substitution in that equation as well, when we
parse the linear combination within that equation.

Ref. dynare#1837
2022-01-17 12:57:37 +01:00
Sébastien Villemot ebf7b6c51d
Clang compatibility fix 2022-01-06 14:35:39 +01:00
Sébastien Villemot a8fce06dc4
PAC: new options “auxname” and “kind” to “pac_model” 2021-12-16 15:40:47 +01:00
Sébastien Villemot ea6fb40db7
PAC: new “pac_target_info” block and “pac_target_nonstationary” operator
Ref. Madysson/estimation-codes#5
2021-12-16 15:40:47 +01:00
Sébastien Villemot 6a31ba4b62
PAC: minor simplification in the matching of the growth expression
Simple variable nodes are already correctly matched by
ExprNode::matchLinearCombinationOfVariables().

Also improve the related documentation.
2021-12-16 15:40:47 +01:00
Sébastien Villemot ae242770f9
PAC: in the backward case, unify h0 and h1 parameters vector into a single vector
There is no reason to keep this distinction.

Additionally, since the data structure is now symmetric with the MCE case,
unify this “h” parameter vector with the “α” parameter vector.
2021-11-23 14:31:03 +01:00
Sébastien Villemot 0f89569f7e
PAC: in the backward case, create an aux. var. for the pac_expectation expression
By the way, refactor the MCE case by merging two routines related to the Z₁ aux. var.
This restores the symmetry with the backward case, now that the latter also has
an aux. var. for the pac_expectation operator. Also store the aux. var. IDs in a
structure common to the backward and MCE cases.
2021-11-23 14:31:03 +01:00
Sébastien Villemot 0e62206203
PAC: drop support for multiple PAC equations associated to a given PAC model 2021-11-23 14:31:02 +01:00
Sébastien Villemot 37a6ed6261
PAC: rethink the relation between PacModelTable and DynamicModel classes 2021-10-29 14:11:30 +02:00
Sébastien Villemot 127361971f
PAC: refactor with new PacModelTable that replaces PacModelStatement(s)
Incidentally, the auxiliary endogenous variable representing Z₁ and created for
PAC MCE models no longer necessarily appear as the first auxiliary variable (so
this is effectively a revert of 64f55e4a5e).
2021-10-29 14:11:30 +02:00
Stéphane Adjemian (Ryûk) 8305b94d29
Fix constant definition in reduced form VAR. 2021-07-21 17:53:55 +02:00
Stéphane Adjemian (Ryûk) c6a7d56b36
Fix constants in var model (it has to be a vector). 2021-07-21 17:53:55 +02:00
Sébastien Villemot a6add6127b
VAR models: output vector of constants in varmatrices.m 2021-07-21 17:53:54 +02:00
Stéphane Adjemian (Ryûk) 6b9d94405c
Return the reduced form of the structural VAR model optionally.
Also

 - changed the name of the generated matlab routine,
 - changed initialization of matrix a0.
2021-07-16 08:33:26 +02:00
Sébastien Villemot 365fb27f3d
New “structural” option to “var_model”
As the name implies, this option allows contemporaneous variables on the RHS.

The A0 matrix for contemporaneous variables is added as a second (optional)
output to the generated var_ar.m file. Note that for reduced-form VAR, this
matrix will be the identity.

Also, the user is now allowed to write the VAR models in a more flexible form:
the LHS must still be a single variable, but the RHS can be an arbitrary
expression (as long as it is linear, obviously). Internally, the preprocessor
now uses derivation to compute the coefficients of the AR and A0. This change
applies to both reduced-form and structural VAR models.

Ref. dynare#1785
2021-07-08 12:55:47 +02:00
Sébastien Villemot 67f4777ac3
Remove support for obsolete syntax: var_model(order = 2) X Y Z; 2021-07-07 18:26:09 +02:00
Sébastien Villemot 5a33699f03
VAR / trend component models: cosmetic changes 2021-07-01 17:52:05 +02:00
Sébastien Villemot 74ef3457b4
Use secure URL for link to GNU licenses 2021-06-09 17:21:00 +02:00
Sébastien Villemot e2d5a83592
Global reindentation 2019-12-20 16:59:30 +01:00
Sébastien Villemot 031c0cff5f
Various code simplifications and modernizations 2019-12-16 19:42:59 +01:00
Sébastien Villemot 2c6fa34a1f
C++17: use structured bindings instead of std::tie whenever possible 2019-09-11 16:40:19 +02:00
Sébastien Villemot 1907249fac
Ask GCC to warn about C-style casts (-Wold-style-cast)
Adapt the code accordingly.
2019-04-23 12:54:11 +02:00
Sébastien Villemot b73d554ad2
Use Unicode copyright symbol (in UTF-8 encoding) 2019-04-16 11:35:31 +02:00
Sébastien Villemot 8a41a75c85
Apply modernize-raw-string-literal from clang-tidy
Use ReplaceShorterLiterals option to enforce replacement of all strings.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-raw-string-literal.html
2019-04-03 16:45:52 +02:00