Commit Graph

315 Commits (e9ffb16ec62b8e6cba2ca1dc84e8c4c65d8a45f0)

Author SHA1 Message Date
Sébastien Villemot bbcbcd1eed
Bytecode: improve interface of methods for looking through Jacobian sparse matrix 2023-10-19 14:50:07 -04:00
Sébastien Villemot b747eff473
Bytecode: remove unused method 2023-10-19 14:19:01 -04:00
Sébastien Villemot 846ed7e829
Bytecode: merge class dynSparseMatrix into Interpreter
These two classes were so entangled that their separation was meaningless.
2023-10-19 13:56:10 -04:00
Sébastien Villemot 654b4e57a2
Bytecode: remove several unused class members of SparseMatrix 2023-10-19 10:59:23 -04:00
Sébastien Villemot 06ac452459
Cosmetics: remove empty list of parameters for lambda functions 2023-10-19 09:56:55 -04:00
Sébastien Villemot d78dea3086
Use __builtin_unreachable() to silent some GCC warnings
This is cleaner than using exit() for that purpose.
2023-10-18 14:28:54 -04:00
Sébastien Villemot 9a0462a8a6
Bytecode: remove a couple of useless casts 2023-10-16 18:06:42 -04:00
Sébastien Villemot 06a7acf19b
Bytecode: enforce consistent typing of size variables 2023-10-16 18:00:11 -04:00
Sébastien Villemot 651fed87be
Bytecode: remove warnings about narrowing (-Wnarrowing) 2023-10-16 17:58:36 -04:00
Sébastien Villemot b0fa610357
Bytecode: remove warnings about uninitialized variables (-Wmaybe-uninitialized)
By the way, in the dynamic case, ensure that solve_algo variable corresponds to
options_.solve_algo; it would previously correspond to
options_.stack_solve_algo, while there is already a separate stack_solve_algo
variable for that purpose.
2023-10-16 17:43:20 -04:00
Sébastien Villemot eae9902cb8
Bytecode: restrict scope of some variables 2023-10-16 15:39:13 -04:00
Sébastien Villemot e4a4d2d8e6
Bytecode MEX: get M_ and options_ through input arguments rather than as global variables 2023-10-11 18:50:32 -04:00
Sébastien Villemot 8cc646fbf6
Bytecode MEX: remove syntax where no MATLAB array is passed
Those arrays were then read via oo_ and options_.

As a consequence, this commit drops the dependency of bytecode MEX upon the oo_
global variable.
2023-10-10 17:44:14 -04:00
Sébastien Villemot dcdbd85b10
Bytecode: fix indentation in output of print_bytecode_{static,dynamic}_model commands 2023-10-10 17:41:38 -04:00
Sébastien Villemot 9525dbe3a8
Bytecode: do not restrict print_bytecode_{static,dynamic}_model to certain values of {stack_,}solve_algo 2023-10-10 17:32:33 -04:00
Sébastien Villemot c329b4ff11
Bytecode: fix bug in print_bytecode_{static,dynamic}_model commands
The FENDEQU tag was not properly handled when printing.
2023-10-10 17:31:48 -04:00
Sébastien Villemot d584317a6a
Bytecode: remove unused methods 2023-10-10 16:54:09 -04:00
Sébastien Villemot 5e7b7ec7b0
Bytecode MEX: remove support for unused “plan” and “pfplan” arguments 2023-10-10 14:49:15 -04:00
Sébastien Villemot bd9943a695
Bytecode: fix memory leak in Evaluate class
The newly-created FBEGINBLOCK_ and FCALL_ instances were freed using a
base-class pointer. But the latter does not have a virtual destructor.

Those class instances are now stored by value in containers, so that the
destructor of the derived class is used.
2023-09-01 14:52:57 +02:00
Sébastien Villemot d6ea315a18
Bytecode: further improve some informative messages 2023-06-15 15:37:45 +02:00
Sébastien Villemot 192f136b96
Bytecode: improve some informative messages 2023-06-13 16:59:08 +02:00
Sébastien Villemot 277c5d4c4f
Bytecode: display real iteration time instead of CPU time 2023-06-13 16:59:08 +02:00
Sébastien Villemot 7c9e261355
Bytecode: fix treatment of maxit option
It would do one extra iteration.
2023-06-13 16:59:08 +02:00
Sébastien Villemot dcf56b89cd
Bytecode: rework message verbosity
Now uses options_.verbosity to decide what to print:
– if options_.verbosity == 0, prints nothing
– if options_.verbosity >= 1, prints iteration counter and duration, and fatal errors
– if options_.verbosity >= 2, additionally print floating point exceptions and
  details about algorithmic decisions
2023-06-13 16:59:07 +02:00
Sébastien Villemot 73b1850cb5
Bytecode: remove unused function 2023-06-13 16:58:06 +02:00
Sébastien Villemot 08d378c244
Bytecode: in evaluate+dynamic mode, return residuals with as many columns as periods
Previously it would also include initial and terminal conditions (i.e.
residuals would have periods+maximum_lag+maximum_lead columns). But we do not
care about residuals at the initial and terminal conditions.

This change is for consistency with the perfect_foresight_problem MEX.
2023-06-12 19:18:44 +02:00
Sébastien Villemot 90d790f1c3
Bytecode: fix error message 2023-06-12 19:18:44 +02:00
Sébastien Villemot d814a4090b
Bytecode: improve display of residuals error during iterations 2023-06-12 15:12:00 +02:00
Sébastien Villemot e86aeaf787
C++20 modernization: use new standard mathematical constants 2023-05-25 19:07:23 +02:00
Sébastien Villemot 030316f2d8
Bytecode: misc simplifications 2023-04-18 22:25:58 +02:00
Sébastien Villemot afe147d88d
Bytecode: the class dynSparseMatrix is no longer derived from Evaluate 2023-04-18 18:10:45 +02:00
Sébastien Villemot e22972849b
Bytecode: make Evaluate::{symbol_table, steady_state} private and const 2023-04-18 17:46:48 +02:00
Sébastien Villemot 4313640f80
Bytecode: allow better compiler optimization of the main evaluation function
Use the __restrict__ GCC extension on double* pointers, to avoid aliasing.

NB: the C “restrict” keyword does not exist in C++.
2023-04-18 17:45:15 +02:00
Sébastien Villemot d71db85c71
Bytecode: move more cached information about current block out of the Evaluate class 2023-04-18 17:44:55 +02:00
Sébastien Villemot 36e8062e25
Bytecode: remove Evaluate::{EQN_block,EQN_block_number} 2023-04-18 17:37:35 +02:00
Sébastien Villemot d789e6a4c5
Bytecode: move storage for variable and parameter values out of the Evaluate class 2023-04-18 17:37:33 +02:00
Sébastien Villemot d0864689d2
Bytecode: minor simplification related to Evaluate::steady_state 2023-04-18 14:23:26 +02:00
Sébastien Villemot 9f29e2f292
Bytecode: add missing floating point exception handling for sqrt and several trigonometric functions 2023-04-07 17:32:36 +02:00
Sébastien Villemot 2740bdee58
Bytecode: remove default clause in switch/case clauses for opcodes
This ensures that we will get a compiler warning reminding us to support
opcodes that may be added in the future.
2023-04-07 16:46:35 +02:00
Sébastien Villemot 1622c74a53
Bytecode: add missing support for cbrt(), abs() and sign() operators 2023-04-07 16:46:35 +02:00
Sébastien Villemot f27c3abd2f
Bytecode: refactor floating point exception handling 2023-04-07 16:46:32 +02:00
Sébastien Villemot fbaa051489
Bytecode: minor simplification 2023-04-07 10:26:57 +02:00
Sébastien Villemot 8128fd4cc3
Bytecode: minor improvements of interfacing with UMFPACK 2023-04-03 18:34:55 +02:00
Sébastien Villemot c4ad1d58e8
Bytecode: minor simplification to debug mode 2023-04-03 18:34:45 +02:00
Sébastien Villemot f0888468e6
Bytecode: optimize memory consumption during iterations
mxArray objects were not properly destroyed within the iteration loop, leading
to higher memory usage. Note that there was no memory leak, because these
objects would be destroyed later by MATLAB when exiting the MEX.
2023-04-03 14:14:33 +02:00
Sébastien Villemot 5a1abb1b87
Bytecode: cleanup memory management for UMPACK memory buffers
There was probably no bug but it is safer this way.
2023-03-31 18:43:16 +02:00
Sébastien Villemot 8dae5393f5
Bytecode: remove unused function 2023-03-31 17:37:31 +02:00
Sébastien Villemot c7d2ea0a62
Bytecode: remove meaningless initializations 2023-02-24 15:29:52 -05:00
Sébastien Villemot 325e6487d4
Bytecode: move computation routines out of the Evaluate class 2023-02-24 15:18:43 -05:00
Sébastien Villemot 17df930eb9
Bytecode: remove unused function 2023-02-24 15:01:35 -05:00
Sébastien Villemot 0e1678c13a
Bytecode: no longer have instruction pointer as a member variable of Evaluate class 2023-02-24 14:30:15 -05:00
Sébastien Villemot 13b3208cdb
Bytecode: move all logic for navigating through the .cod file into the Evaluate class 2023-02-23 17:37:08 -05:00
Sébastien Villemot aaab993ccf
Bytecode: merge CodeLoad class into Evaluate 2023-02-23 11:21:22 -05:00
Sébastien Villemot 895ce96c61
Bytecode: fix memory management for FBEGINBLOCK and FCALL tags
FCALL was not properly deallocated, hence leading to a memory leak.
Also simplify the handling of FBEGINBLOCK through a std::unique_ptr.
2023-02-21 16:58:45 -05:00
Sébastien Villemot 1ad6b29936
Bytecode: misc minor simplifications 2023-02-21 16:31:08 -05:00
Sébastien Villemot 24b2976ac2
Bytecode: move CodeLoad class out of the preprocessor 2023-02-21 16:02:21 -05:00
Sébastien Villemot 05ba2970be
Bytecode: diminish the number of data members in Evaluate class 2023-02-17 13:46:41 -05:00
Sébastien Villemot c3e1480a52
C++17 modernization: use std::extent_v to get raw arrays size
This can prevent mistakes when the array is modified.
2023-01-24 13:43:02 +01:00
Sébastien Villemot 4ecc78a931
Preprocessor: drop unused per-block max lead/lag fields 2023-01-17 14:43:56 +01:00
Sébastien Villemot 0c5c96e724
Bytecode w/ block decomposition: no longer output derivatives w.r.t. exogenous and endogenous outside the block 2023-01-17 14:24:02 +01:00
Sébastien Villemot f84753025d
Bytecode: the block and non-block versions now coexist in parallel
As a consequence, a new “block_decomposed” option of the bytecode MEX has been
introduced to explicitly select the block-decomposed version.

Note that we do not always use the “block_decomposed” option even when the
“block” option has been passed to the user, in situations where the block
decomposition brings nothing (e.g. when evaluating the residuals of the whole
model).
2023-01-09 15:20:46 +01:00
Sébastien Villemot 24d7f569f1
Bytecode MEX: fix compilation under GCC ⩾ 11
Problem introduced in previous commit.
2022-07-29 14:30:45 +02:00
Sébastien Villemot e22ca82ab6
Bytecode MEX: drop the ErrorMsg class and integrate most of its members inside the Evaluate class 2022-07-29 13:04:31 +02:00
Sébastien Villemot 034a981daa
Bytecode MEX: streamline error handling 2022-07-29 13:04:29 +02:00
Sébastien Villemot 4ec6c0dab4
Bytecode MEX: streamline preprocessor guards in includes 2022-07-29 12:40:33 +02:00
Sébastien Villemot 0076644bda
Bytecode MEX: fix bug with PowerDeriv printing introduced in ff85fc6489 2022-07-28 17:13:23 +02:00
Sébastien Villemot 7c4dc1abce
Bytecode MEX: in error messages, revert back to default floating point format
A move to fixed format was erroneously made in
4893f0e82c and
ff85fc6489, where stream formatting of floating
points has been replaced by the use of std::to_string().
2022-07-28 17:10:12 +02:00
Sébastien Villemot 6e1635658f
Bytecode MEX: split out code for dealing with variable names into a dedicated BasicSymbolTable class 2022-07-28 16:56:40 +02:00
Sébastien Villemot 5df3fde95e
Bytecode MEX: streamline function for adding tildes below FP error 2022-07-28 15:48:21 +02:00
Sébastien Villemot ff85fc6489
Bytecode MEX: refactor the routines that display expressions in human-readable form
In particular, minimize the number of parentheses written, using the same
algorithm as in the preprocessor.
2022-07-27 18:06:08 +02:00
Sébastien Villemot 1b13bb2e6e
Bytecode MEX: simplify type for storing list of instructions 2022-07-26 18:27:23 +02:00
Sébastien Villemot 9d84048710
Bytecode MEX: fix bug introduced in 8c01912a50
Use an iterator wrapped inside std::optional instead of a possibly-singular
iterator, because the latter has undefined behaviour.

By the way, pass arguments by const reference.
2022-07-26 16:35:06 +02:00
Sébastien Villemot dc224e71ed
Bytecode MEX: fix error messages for derivatives w.r.t. exogenous / exogenous deterministic
The wrong type was used for querying symbol names.
2022-07-26 16:35:06 +02:00
Sébastien Villemot 8c01912a50
Bytecode MEX: simplify printing of numerical errors in expression
In particular, no longer rely on a duplicate implementation of the evaluator to
locate where the NaN or Inf is produced. Rather directly pass the pointer to
the faulty operator.
2022-07-25 18:07:18 +02:00
Sébastien Villemot a8351130f1
Bytecode MEX: bugfix in error message printing
Class Evaluate had data members with the same name as members of
ErrorMsg (which it derives from). In practice, this means that the data members
from ErrorMsg could be unitialized when displaying error messages.
2022-07-25 15:07:52 +02:00
Sébastien Villemot feb10b75e6
Bytecode MEX: minor fix to debug mode 2022-07-20 16:19:49 +02:00
Sébastien Villemot e87d643084
Preprocessor: various refactorings, mainly bytecode-related 2022-07-20 16:18:02 +02:00
Sébastien Villemot b29dde227d
Preprocessor: various refactorings (mainly bytecode) 2022-07-08 16:05:33 +02:00
Sébastien Villemot b3cff2d34d
Bytecode: remove incomplete/buggy support for exogenous deterministic 2022-07-05 13:02:17 +02:00
Sébastien Villemot 8be6f55bf6
Bytecode MEX: remove unused function parameters 2022-07-05 12:12:08 +02:00
Sébastien Villemot b05ef5dd7f
Bytecode MEX: remove unused function 2022-07-05 12:11:32 +02:00
Sébastien Villemot 8dba4ec68c
Bytecode: minor fixes to debug mode 2022-06-24 12:53:19 +02:00
Sébastien Villemot 8a0eb76b1b
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:51:08 +02:00
Sébastien Villemot 0107365f6a
Bytecode: stop using unsigned integers where signed ones avoid unnecessary casts 2022-06-20 17:52:01 +02:00
Sébastien Villemot 8bee62fa5e
Bytecode: directly use several enums inside instruction classes 2022-06-20 17:51:59 +02:00
Sébastien Villemot a2d0ac3586
Bytecode: remove unused expression types 2022-06-17 16:32:59 +02:00
Sébastien Villemot 0719f749e7
Bytecode: remove unused opcodes 2022-06-17 16:32:50 +02:00
Sébastien Villemot 3cc4aeb826
Preprocessor: split CodeInterpreter.hh into two headers 2022-06-16 18:05:00 +02:00
Sébastien Villemot 06f665e231
Perfect foresight: LBJ now available under stack_solve_algo=1 (with/without block/bytecode)
Previously, LBJ was available:

– under stack_solve_algo=6 when neither block nor bytecode were present
– under stack_solve_algo=1 with either block or bytecode (but the documentation
  was not making it clear that it was LBJ)

This commit merges the two values for the option, and makes them
interchangeable. LBJ should now be invoked with stack_solve_algo=1 (but
stack_solve_algo=6 is kept for compatibility, and is a synonymous).
2022-06-15 15:06:33 +02:00
Sébastien Villemot 9cc5a5576e
Bytecode: some clean ups around checks for “stack_solve_algo” value 2022-06-15 14:28:41 +02:00
Sébastien Villemot 5db070e9dd
Bytecode: fix inconsistency in memory manager
The variable “gap” is compared to zero, so the intent probably was that it
could be negative. But size_t is an unsigned type. Rather use a signed type.
2022-06-07 17:26:45 +02:00
Sébastien Villemot 41ccfd4068
Bytecode: use braces (instead of $ and £) to highlight floating-point errors in expressions 2022-05-05 17:10:27 +02:00
Sébastien Villemot b4ce69db3a
Remove options_.slowc field
There was no user interface, and the feature that it provides has lost
relevance over time.

Note that algorithms for block and/or bytecode still internally use some
equivalent of this parameter, but its initial value will no longer be
modifiable (which could lead to bugs, see commit
e49e7e906f).
2022-03-31 17:39:43 +02:00
Sébastien Villemot 2d73ae2971
Bytecode: fix typo 2022-03-16 15:00:09 +01:00
Sébastien Villemot 96fb676be7
Bytecode: fix stack_solve_algo=4 when a “solve backward/forward” block follows a “solve two boundaries” block
When solving a “Solve two boundarise” block with stack_solve_algo=4, the
“slowc” variable is modified. This would affect the resolution of further
“solve backward/forward” blocks, which would yield results.

The fix consists in saving and restoring “slowc”.
2022-03-15 17:42:03 +01:00
Sébastien Villemot 65e18fe883
Bytecode: fix stack_solve_algo=4 on linear blocks
Only one iteration is performed on linear blocks. But in the case of
stack_solve_algo=4 it is not enough, since it will not find the right optimal
path lenght at the first iteration (even though that optimal path length is
ufnitary).
2022-03-01 11:29:29 +01:00
Sébastien Villemot dbbbb75874
Bytecode: fix typo, replace “substract” by “subtract” 2022-02-28 18:47:20 +01:00
Sébastien Villemot 67a003aa73
Bytecode: fix stack_solve_algo=1 (relaxation method)
There were various issues with the construction of sparse submatrices.

By the way, refactor and document the code to make it more readable.
2022-02-28 18:47:20 +01:00
Sébastien Villemot 811e53f9ad
Bytecode: document matrix computation routines 2022-02-28 18:47:20 +01:00
Sébastien Villemot 59b8ee9c33
Bytecode: remove unused matrix subtraction routine 2022-02-28 18:47:20 +01:00