Commit Graph

76 Commits (b1e4884237376fdce06265b7f96fb63e0bd8b224)

Author SHA1 Message Date
Sébastien Villemot b1e4884237
🐛 sign(0) was returning 1 instead of 0 with use_dll
The C99 copysign() function was used in the generated C output, but that
function does not correctly handle zero. Replace it by a custom sign()
function.
2023-04-07 16:38:23 +02:00
Sébastien Villemot 7c6402cc34
DataTree: optimize the filling of node maps
Use map::{try,}emplace() instead of operator[], which should in theory be
slightly faster.
2023-03-23 16:10:40 +01:00
Sébastien Villemot 62c455ff56
Misc simplifications using STL algorithms 2023-02-28 16:27:29 +01:00
Sébastien Villemot 762243c705
Julia: drop get_power_deriv function from module
The function is now provided separately by Dynare.jl.
2022-11-02 15:49:56 +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 198ff70bce
Simplify strsplit() using std::string_view
By the way:
– improve the semantics by having a consistent treatment of empty substring
  components (previously, only the last one was ignored)
– move it to DataTree to make it more accessible from elsewhere (even though
  ideally it should be in a “utilities” namespace).
2022-10-11 16:23:11 +02:00
Sébastien Villemot 157c67e04b
New helpers to simplify common operations with derivation IDs 2022-07-12 16:30:45 +02:00
MichelJuillard 3e1f9dbb82 use @inbounds blocks instead of @inbounds for each line 2022-07-12 13:07:33 +02:00
MichelJuillard a4556896db Julia functions Float64 -> <: Real 2022-07-12 11:15:51 +02:00
Sébastien Villemot f38c8278ae
Refactor methods for writing static and dynamic files
– factorize common code between the static and the dynamic version
– reorganise language-specific code into dedicated functions
– use a function template in the main helper to do some computations
  at compile-time (using constexpr features)
2022-07-11 22:29:28 +02:00
Sébastien Villemot c3fc5b1dd7
Enable -Wunused-parameter
As a consequence, add many [[maybe_unused]] attributes for legitimate
cases (mainly in virtual functions).
2022-06-24 17:11:48 +02:00
Sébastien Villemot 13dc0a1144
Use operator""s to replace some calls to std::string constructor
By the way, remove other unnecessary calls to that constructor.
2022-06-22 12:47:11 +02:00
Sébastien Villemot a85730313c
Split CodeInterpreter.hh into two headers
– a generic one: CommonEnums.hh
– and a bytecode-specific one: Bytecode.hh

By the way, rename global constant “near_zero” into “power_deriv_near_zero”,
for clarity.
2022-06-16 17:53:23 +02:00
Sébastien Villemot 25a32b1a32
Cosmetics 2022-05-19 12:27:44 +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 ef02b79486
Various minor simplifications 2022-05-04 17:36:59 +02: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 d15b2110a0
Add erfc() primitive
Closes: #85
2021-12-07 15:19:40 +01:00
Sébastien Villemot 5498ce98ee
Use NumConstNode* type for DataTree constants (previously they were just expr_t) 2021-07-21 17:53:54 +02:00
Sébastien Villemot ed31d1cb5e
Remove unused functions 2021-07-21 16:33:23 +02:00
Sébastien Villemot c9c36c037a
New preprocessor option “nocommutativity”
This option tells the preprocessor not to use the commutativity of addition and
multiplication when looking for common subexpressions.

As a consequence, when using this option, equations in various outputs (LaTeX,
JSON…) will appear as the user entered them.

There is however a potential performance cost to using this option, yet to be
determined.

Ref. dynare#1788
2021-07-13 14:35:10 +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 12b61e4817
Bugfix in DataTree::writeToFileIfModified()
If the old file and the new contents shared a common prefix, then the output in
the generated file would be truncated at the start.

Ref. DynareJulia/Dynare.jl#1
2021-04-26 14:10:47 +02:00
MichelJuillard 9773bafc5b Julia: write definition of get_power_deriv inside generated static/dynamic files 2021-04-26 10:52:18 +00:00
Sébastien Villemot 4cfc7a563b
Julia: do not overwrite Static/Dynamic files if contents has not changed
Ref. DynareJulia/Dynare.jl#1
2021-04-22 18:03:47 +02:00
Sébastien Villemot 7b3df21f11
DataTree::operator=(): fix crash when symbol ID ordering of model local variables does not correspond to the recursive ordering in the model block
Ref. dynare#1782
2021-04-16 17:34:13 +02:00
Sébastien Villemot a377fc8398
Fix various potential bugs with model local variables
Many recursive function on ExprNodes were not correctly recursing into the
definition of model local variables.
2020-09-29 18:41:17 +02:00
Sébastien Villemot 633b89db64
use_dll: remove hack for Microsoft Visual C++
We don’t support that compiler, and in any case it should support C99.
2020-06-23 16:00:55 +02:00
Sébastien Villemot ad5e196d30
Block decomposition now compatible with 'use_dll' option 2020-06-23 15:13:04 +02:00
Sébastien Villemot 7b11898689
use_dll: merge the two generated C source files into a single one
Also, do various other cosmetic/simplification changes.
2020-05-29 16:12:01 +02:00
Sébastien Villemot e88c05e3b8
Change prototype of DataTree::AddEqual()
This permits some simplifications.
2020-04-02 19:19:57 +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 047b397899
Simplify x+y-y in x
Note that this actually corresponds to 4 different abstract syntax trees:
— (x+y)-y
— (y+x)-y
— (x-y)+y
— y+(x-y)
2019-12-12 16:19:15 +01:00
Sébastien Villemot d747b53a8b
Simplify x*y/y in x
Note that this actually corresponds to 4 different abstract syntax trees:
— (x*y)/y
— (y*x)/y
— (x/y)*y
— y*(x/y)
2019-12-12 16:19:15 +01:00
Sébastien Villemot 50275f3588
Simplify x-(-y) in x+y 2019-12-12 16:19:15 +01:00
Sébastien Villemot f24f28b2b2
Simplify x/(1/y) in x*y 2019-12-12 16:19:15 +01:00
Sébastien Villemot 1d3265acb7
C++17: further code simplifications (assignments in if) 2019-12-12 16:19:14 +01:00
Sébastien Villemot 0c755460b1
Use std::filesystem instead of boost::filesystem
Note that there is no equivalent of boost::filesystem::unique_path(), so I
implemented ModFile::unique_path() which does something similar.
2019-09-11 14:47:48 +02:00
Houtan Bastani 0c1373bc5e
stop processing when certain functions are used in a linear context on endogenous/exogenous variables. closes dynare#1537 2019-09-10 12:37:28 +02:00
Sébastien Villemot 4594fdd0fd
More comment improvements in relation to diff operator expansion/substitution 2019-08-20 18:22:02 +02:00
Houtan Bastani ae0a91256a
add cubic root to dynare language 2019-07-15 12:18:26 -04:00
Houtan Bastani 21fe0f4bdc
avoid cast warnings when compiling boost headers 2019-04-23 14:57:03 +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
Houtan Bastani 7c9f272e15
always substitute diffs of expressions that contain leads. closes #21 2019-03-05 12:43:54 +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
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 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