Commit Graph

1011 Commits (e9ffb16ec62b8e6cba2ca1dc84e8c4c65d8a45f0)

Author SHA1 Message Date
Sébastien Villemot d3afa980aa
MEX: better type definition for long SuiteSparse integers under Windows 2023-04-03 18:31:04 +02:00
Sébastien Villemot d078810625
MEX: remove obsolete MSVC check 2023-04-03 14:59:36 +02:00
Sébastien Villemot a45b00fa69
MEX: better type definition for BLAS/LAPACK integers in C and C++
int64_t on 64-bit machines better expresses the intent than ptrdiff_t. This is
also more consistent with what is done in Fortran.
2023-04-03 14:58:07 +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 403db2cc64
Bytecode MEX: under Octave, use system-wide umfpack.h instead of our own version 2023-03-31 16:18:27 +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 7922fc011e
perfect_foresight_problem MEX: move to the sparse representation
Ref. #1859
2023-01-24 13:43:00 +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 8f1a4cb363
Drop block-decomposed first-order perturbation solution and kalman filter 2023-01-13 16:57:49 +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 9c4dd1b1d0
Remove irrelevant comment
[skip ci]
2023-01-04 15:00:27 +01:00
Sébastien Villemot d574705b4a
Design and performance improvement to solve_algo={12,14}
Use the new time-recursive block decomposition computed by the preprocessor
for:
- the simulation of backward models with “simul_backward”
- the perfect foresight simulation of purely backward/forward/static models

Also note that in this case, the preprocessor now defaults to “mfs=3” (i.e. it
minimizes the set of feedback variables and tries to renormalize equations).

This replaces the previous algorithm based on Dulmage-Mendelsohn (dmperm), plus
an ad hoc identification of some equations that can be evaluated (those with a
LHS equal to a variable, the log of a variable, or the diff-log of a variable).

By the way, the block_trust_region MEX has been modified so that it accepts a
boolean argument to decide whether it performs a Dulmage-Mendelsohn
decomposition (if not, then it performs a simple trust region on the whole
nonlinear system).

This provides a significant performance improvement (of almost an order of
magnitude for solve_algo=14 on a 700 equations model).
2022-11-30 14:47:57 +01:00
Sébastien Villemot 10fdc42516
block_trust_region MEX: add support for sparse Jacobian
If the function to be solved returns a sparse Jacobian, simply convert it to a
dense representation.
2022-11-30 14:47:57 +01:00
NormannR a245fbb390 Implements a Fortran update of the states variance-covariance matrix for the Kalman filter 2022-11-14 16:24:46 +00:00
Johannes Pfeifer fe0606ae06 logarithmic_reduction.m: use positive penalty add-on 2022-10-11 16:13:03 +02:00
NormannR afb044c23e Fix cycle reduction:
(i) making the norms consistent between cycle_reduction and its test;
(ii) remove hard errors in cycle_reduction Fortran and Matlab routines
2022-10-11 12:11:30 +02:00
NormannR 855887b249 Implements a logarithmic reduction Fortran routine and the associated test 2022-10-11 12:11:06 +02:00
Normann Rion d17204cc84 Implements a cycle reduction Fortran routine and the associated test.
The Fortran routine replaces the former Matlab code in matlab/cycle_reduction.m
2022-10-03 14:38:12 +02:00
NormannR c6d5c48ff7 Local state-space iteration at order 3: multi-thread 3rd-order version with and without pruning 2022-08-30 14:06:19 +02: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 16eabbbc4e
block_trust_region MEX: improve treatment of non-square blocks in Dulmage-Mendelsohn decomposition
– before erroring out, check whether the residuals for the block are already
  zero (in which case, move to next block)
– improve error message that is printed otherwise

Note that trying to solve under-determined blocks (as in dynare_solve.m) would
require too many changes in the existing code, so let’s leave it out.

Closes: #1851
2022-07-22 12:43:38 +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 888a87312d
Enable -Wunused-parameter for C++ MEX
Except for libdynare++, since Dynare++ is not ready (and is probably not worth
fixing by adding [[maybe_unused]] tags).
2022-07-05 12:12:53 +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 218bb1a15f
k_order_welfare MEX: check number of arguments 2022-07-05 11:55:40 +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 5ccd5f2613
Revert "More explicit message when the Dulmage-Mendelsohn decomposition returns a non-square block"
This reverts commit fa71d4712d.

Ref. #1851
2022-06-16 18:05:14 +02:00
Sébastien Villemot 3cc4aeb826
Preprocessor: split CodeInterpreter.hh into two headers 2022-06-16 18:05:00 +02:00
Sébastien Villemot fa71d4712d
More explicit message when the Dulmage-Mendelsohn decomposition returns a non-square block
Closes: #1851
2022-06-16 15:53:45 +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
Stéphane Adjemian (Ryûk) f7204e6ec8
Bug fix (pruning at second order in estimation).
Closes #1853.
2022-05-13 11:39:49 +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 ce2c1e0d30
No longer use C++ UTF-8 string literals
They don’t bring any added value, and break compilation in C++20 mode (because
they are then of type “const char8_t *” which is distinct from “const char *”).
2022-05-04 18:32:52 +02:00
Sébastien Villemot 10af04c6d8
Use Unicode copyright symbol (in UTF-8 encoding) in all source files
It is now supported by the MATLAB editor (as of R2022a).

The old ASCII notation is left in some files that we copy as-is from other
sources (e.g. in the contrib/ and m4/ subdirectories).

The particles submodule is not updated at this point, because it is in an
inconsistent state.

[skip ci]
2022-04-13 14:54:25 +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 c5a3658110
Block trust region: cosmetics
In particular, avoid using the deprecated dble() function. Rather use the
real() cast function, with the appropriate kind parameter.
2022-03-29 10:34:35 +02:00
Stéphane Adjemian (Ryûk) b9bc1e7cb1
Revert update if residuals or jacobian have NaNs (block_trust_region). 2022-03-25 19:42:40 +01:00
Stéphane Adjemian (Ryûk) 79cad99446
Harmonise exit codes and fix convergence test. 2022-03-25 19:42:40 +01:00
Stéphane Adjemian (Ryûk) f2bf98ee76
Return the value of info as a third argument (block_trust_region). 2022-03-25 19:42:40 +01:00
Sébastien Villemot 8c16d1745e
block_trust_region MEX: first part of handling complex values returned by solved function
If solved function returns complex values (with nonzero imaginary part), turn
them into NaNs. This mimics the behaviour of the use_dll case.

Next step will be to adapt the trust region algorithm to diminish radius when
there are NaNs.

Incidentally, bump the required GCC version to 9, since we use the %re and %im
components of complex values in Fortran.
2022-03-21 18:55:42 +01:00
Sébastien Villemot d5472d2338
Tighten input sanity checks of various MEX files
Note that the unitary test in lyapunov_solver.m that checks sparse matrix input
had to be removed. Previously, this test was passing by chance (because the
sparse test matrices had actually no zero element, hence the internal double
float storage was the same as in the dense case). Now it consistently fails
with the additional checks in disclyap_fast MEX.
2022-03-18 22:49:46 +01:00
Sébastien Villemot 4f6d8a198a
k_order_perturbation MEX: convert complex elements of residuals or derivatives matrices to NaNs 2022-03-18 16:45:33 +01: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
Sébastien Villemot a7cc466285
Bytecode: fix bug in sparse matrix multiplication routines
Since those routines compute Aᵀ·B, the number of rows of the output is equal to
the number of columns of A.
2022-02-28 12:18:58 +01:00
Sébastien Villemot 8536b63827
Bytecode: remove superfluous debug information 2022-02-18 14:17:37 +01:00
Sébastien Villemot 972461c326
Bytecode: add debugging information about input arguments 2022-02-17 17:41:10 +01:00
Sébastien Villemot a376d8c9fe
Fix steady state computation with bytecode+block and solve_algo ⩽ 4 or ⩾ 9
– Temporary terms were not correctly passed between blocks
– solve_algo ⩾ 9 was incorrectly passed through bytecode own’s solver instead
  of through dynare_solve
2022-02-17 17:28:37 +01:00
Sébastien Villemot ceb3ec2487
Bytecode: remove unused constructors 2022-02-15 16:54:41 +01:00
Sébastien Villemot 863fa2de1c
Bytecode: perfect foresight simulation of *linear* “Solve forward simple/complete” blocks was giving was results 2022-02-15 16:54:41 +01:00
Sébastien Villemot 803e3721ec
Bytecode: correctly handle M_.{endo_names,exo_names,param_names}, which are now cell arrays 2022-02-14 15:06:07 +01:00
Sébastien Villemot 92e82cfa0a
Bytecode: remove unused function prototype 2022-02-14 14:40:34 +01:00
Sébastien Villemot 188df7711d
Bytecode: fix simulation of blocks “Solve forward/backward complete” with stack_solve_algo={0,1,4}
The problem would also manifest at steady state computation with solve_algo=6.

It could crash or give incorrect results.
2022-02-11 12:00:25 +01:00
Sébastien Villemot d74cb031d2
Bytecode: fix error message about convergence failure that can happen in Solve Backward Complete as well 2022-02-10 17:27:07 +01:00
Sébastien Villemot cdb4f872b2
Bytecode: fix crash with stack_solve_algo=1 on “Solve forward/backward” blocks 2022-02-10 17:15:24 +01:00
Sébastien Villemot ef6e4c7745
Bytecode: remove unused code 2022-02-10 16:58:39 +01:00
Sébastien Villemot 0caefa1593
Bytecode: exit gracefully when M_ does not exist 2022-02-09 14:32:25 +01:00
Sébastien Villemot 8d3e0587dc
k_order_mean MEX: check number of output arguments
Incidentally, this fixes a gfortran warning
2022-02-04 14:38:30 +01:00
Sébastien Villemot 964763ef4d
pthread Fortran interface: fix internal type for representing pthread_t structure 2022-02-04 12:33:19 +01:00
Sébastien Villemot 39f47dc957
local_state_space_iteration_k MEX now uses the Fortran code (instead of the C++ code)
Closes: #1802
2022-02-04 11:49:46 +01:00
NormannR 5f828e241f Parallelizes local_state_space_iteration_fortran 2022-01-31 18:44:48 +01:00
Sébastien Villemot 0c68e7336b
perfect_foresight_problem MEX: error out properly when called MATLAB function triggers an exception
Closes: #1832
2022-01-03 18:11:31 +01:00
Sébastien Villemot 5f675eee18
Add erfc() primitive 2021-12-07 17:00:59 +01:00
Normann Rion cf829fb28e
A few fixes for k-order welfare assesment in `evaluate_planner_objective`
As suggested in !1962
2021-12-07 12:19:30 +01:00
Sébastien Villemot 10698ba896
Fix building of source package
Bug introduced in 06fd42c19b.
2021-11-26 19:15:27 +01:00
Sébastien Villemot 06fd42c19b
Drop the dynare_simul_ MEX in favour of the new Fortran k_order_simul MEX 2021-11-26 17:37:53 +01:00
NormannR f889a25e86 Amend the k_order_welfare routine for it to return the adequate output variables 2021-11-24 17:16:03 +01:00
NormannR 45aad05670 Implements a Fortran routine `k_order_moment` to compute the k-order unconditional moment of the vector of endogenous variables using simulation 2021-11-24 17:09:12 +01:00
NormannR cb5971d60f Fix typo in local_state_space_iteration_fortran 2021-11-24 14:32:37 +01:00
Sébastien Villemot ebec02c6e4
local_state_space_iteration_2 MEX: yet more fixes to comments
In particular, use ε instead of u in mathematical expressions for consistency
with the C++ variable name.
2021-10-22 17:57:29 +02:00
Sébastien Villemot 0be7e0a0d7
local_state_space_iteration_2 MEX: more fixes to comments 2021-10-21 16:34:57 +02:00
Sébastien Villemot 05ea09eee9
local_state_space_iteration_2 MEX: error out properly when trying to use with BLAS+MATLAB+parallelization
By the way, rename the C preprocessor symbol so that it is undefined by
default.
2021-10-20 15:50:34 +02:00
Sébastien Villemot e3b1f9e79a
local_state_space_iteration_2 MEX: various fixes to comments 2021-10-20 15:39:58 +02:00
Sébastien Villemot ce282dc29c
local_state_space_iteration_2 MEX: fix bug when there are more shocks that states
The code that computes ghx·yhat+ghu·u (both with and without pruning) was
making the implicit assumption that q⩽n, i.e. that the number of shocks is less
than or equal to the number of states. If q>n, it would try to read invalid
memory references in ghx and yhat, and would thus either crash or return dummy
results.

Closes: #1820
2021-10-14 16:18:17 +02:00
Sébastien Villemot e722e908e5
k_order_simul+local_state_space_iteration_fortran MEX: fix gfortran warnings 2021-09-24 16:44:40 +02:00
Normann Rion 6475c52b3d Implements k-order simulation routine in Fortran (Ref: #1802)
`k_order_simul` may replace `dynare_simul_` in the long run
2021-09-24 09:11:15 +02:00
Normann Rion a576bdd03f Fixing the header doc and automake files for the local state space iteration Fortran MEX 2021-09-24 09:11:06 +02:00
Sébastien Villemot 7083f1d692 Merge branch 'local_state_space_it' into 'master'
Implements the Fortran replacement of local_state_space_iteration_k (Ref #1802)

See merge request Dynare/dynare!1918
2021-09-22 15:54:17 +00:00
NormannR cab65dabb5 Implements `local_state_space_iteration_fortran`, the Fortran replacement of `local_state_space_iteration_k` (Ref #1802)
- Creates the library `libkordersim` with all the relevant Fortran routines to `folded_to_unfolded_dr` and `local_state_space_iteration_fortran`
   - Implements `folded_to_unfolded_dr`, which converts folded decision rule matrices to their unfolded counterparts
2021-09-22 16:28:46 +02:00
Sébastien Villemot 271d80abee
Bytecode: release the lock on dynamic.bin when an exception occurs
Closes: #1815
2021-09-20 17:28:43 +02:00
Sébastien Villemot 67c205e0a4
Fortran 2008: add interface for mxCreateStructMatrix
Needed by Normann.
2021-09-14 17:05:07 +02:00
Stéphane Adjemian (Ryûk) e72dde69d3
Add option for trust region algorithm (mex).
trust_region_initial_step_bound_factor is determinining thye initial
step bound. Default value is 100 (previous hard coded value was 1).
2021-07-23 19:44:16 +02:00
Johannes Pfeifer 66dcef2754 k_order_welfare.cc: remove gratuitous screen output 2021-07-22 15:12:59 +02:00
Normann Rion 3d27672c58
kth-order approximation of conditional welfare
Partially addresses issue #1680:
- unconditional welfare resorts to dynare++ simulation tools, which shall be updated very soon
TO DO:
- implement a function computing kth-order approximation of simulated moments of y
2021-06-15 15:04:31 +02:00
Sébastien Villemot a7203095db
A_times_B_kronecker_C MEX: don’t bother adding “only” clauses to “use” directive 2021-06-14 15:28:34 +02:00
Sébastien Villemot 766fff88f6
Use secure URL for link to GNU licenses 2021-06-09 17:35:05 +02:00
Sébastien Villemot a40a9b079c
sparse_hessian_times_B_kronecker_C MEX: bugfix relating to number of rows of B and C
In practice however, it seems that this bug never hits, because B and C always
have the same number of rows when the MEX is called.
2021-06-08 17:58:40 +02:00
Sébastien Villemot 3bd3c78e0e
A_times_B_kronecker_C MEX: rewrite in Fortran 2021-06-04 12:58:39 +02:00
Sébastien Villemot c4ca0ef0b2
Fortran MEX: remove useless return statements after calls to mexErrMsgTxt() 2021-06-04 12:58:39 +02:00
Sébastien Villemot f90a8ab070
Fortran MEX: mark array pointers returned by MEX functions as contiguous
This can make a difference when the return value of those function is directly
passed to a BLAS/LAPACK function.

On the other hand, if the return value is first stored in a pointer variable,
then it seems necessary to explicitly say that this pointer is also contiguous.
2021-06-04 12:58:39 +02:00
Sébastien Villemot dc2695a11f
mjdgges and block_trust_region MEX: optimise by marking some function arguments as contiguous
This avoids unnecessary array copies before calling BLAS/LAPACK functions.
2021-06-04 12:58:36 +02:00
Sébastien Villemot 3a2335975a
Fortran MEX: add missing “implicit none” in blas and lapack modules 2021-06-04 12:57:47 +02:00
Sébastien Villemot 45181cfd97
Fortran MEX: add interface for dgemm 2021-06-04 12:57:32 +02:00
Sébastien Villemot c9eb6920c9
local_state_space_iteration_k MEX: fix bug in output
In its output, the MEX was returning values for all endogenous variables, but
it was used in a context where only the variables from oo_.dr.restrict_var_list
were expected (as is done with local_state_space_iteration_2 MEX).

This commit fixes this discrepancy, and also fixes the test that was checking
that both MEX are returning the same output.

Closes: #1768
2021-03-10 13:45:29 +01:00
Sébastien Villemot 1a0ee5f055
Bytecode / sparse transpose: bug fix
The Jc vector has n+1 elements, where n is the number of columns. Moreover, the
size passed to memset() was wrong.
2021-02-09 16:05:11 +01:00
Sébastien Villemot c9f6d3a626
Bytecode: more simplifications and modernizations 2021-02-09 16:00:53 +01:00
Sébastien Villemot 4a1dbc5ca4
Bytecode: fix bug introduced in previous commit
map::at() does bound checking, and throws an exception if out-of-range,
contrary to [] operator which returns a new element.
2021-02-03 19:52:25 +01:00
Sébastien Villemot 4893f0e82c
Bytecode: various simplifications and modernizations 2021-02-03 18:10:31 +01:00
Sébastien Villemot 30cfb0b03c
Bytecode: bugfix in conditional forecast 2021-02-01 17:54:36 +01:00
Sébastien Villemot 967966876f
Bytecode: remove obsolete LINBCG stuff 2021-02-01 15:26:33 +01:00
Sébastien Villemot 743469bfd7
Bytecode: remove stuff for creating a standalone debugging executable
This code no longer compiles. And it’s possible to debug the MEX directly.
2021-02-01 15:26:33 +01:00
Sébastien Villemot bb5f58f55f
Bytecode: remove useless constant redefinition 2021-02-01 15:26:33 +01:00
Sébastien Villemot eb29dc003a
Bytecode: remove CUDA-specific stuff 2021-02-01 15:26:31 +01:00
Sébastien Villemot 5ef440ad9b
Bytecode: remove MSVC++ specific portions 2021-02-01 14:50:46 +01:00
Sébastien Villemot f9f50ff19a
Bytecode: port to C++11 using keyword
Performed using modernize-use-using from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-using.html
2021-02-01 14:50:46 +01:00
Sébastien Villemot 47357bb432
Bytecode: port to C++11 nullptr keyword
Performed using modernize-use-nullptr from clang-tidy.

Manual intervention to remove old-style C casts to nullptr.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
2021-02-01 14:50:42 +01:00
Sébastien Villemot a2186b06b8
Bytecode: port to C++11 syntax for default constructors
Performed using modernize-use-equals-default from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-equals-default.html
2021-02-01 14:50:42 +01:00
Sébastien Villemot 1aa0286f6d
Bytecode: port to C++11 emplace_back() method on containers
Performed using modernize-use-emplace from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-emplace.html
2021-02-01 14:50:42 +01:00
Sébastien Villemot 93c6cb1c3c
Bytecode: use bool literals
Performed using modernize-use-bool-literals from clang-tidy

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-bool-literals.html
2021-02-01 14:50:42 +01:00
Sébastien Villemot 1a4340cb80
Bytecode: port to C++11 auto keyword
Performed using modernize-use-auto from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-auto.html
2021-02-01 14:50:39 +01:00
Sébastien Villemot 63e922f637
Bytecode: port some constructors to pass-by-value using C++11 move semantics
Performed using modernize-pass-by-value from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-pass-by-value.html
2021-02-01 14:50:10 +01:00
Sébastien Villemot 7840d1396e
Bytecode: port to C++11 range-based for loops
Performed using modernize-loop-convert from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-loop-convert.html
2021-02-01 14:50:07 +01:00
Sébastien Villemot 2f587cf5c3
Bytecode: use C++ headers
Performed using modernize-deprecated-headers from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-deprecated-headers.html
2021-02-01 12:28:50 +01:00
Sébastien Villemot c050325e3d
Bytecode: C++17 modernization / convert the remaining enums to enum classes 2021-02-01 12:10:47 +01:00
Sébastien Villemot bc053018a0
Remove risky steady state (unfinished) code
Incidently, remove the possibility of passing model derivatives as arguments to
the k_order_perturbation. That possibility was only used by the risky steady
state code.

Closes: #1338
2021-01-22 11:32:36 +01:00
Stéphane Adjemian (Odysseus) 0e1c9312e2
Merge remote-tracking branch 'Dynare/master' into enterprise 2021-01-11 11:06:55 +01:00
Sébastien Villemot 55e25bcb7f
perfect_foresight_problem MEX: check the return code of mexCallMATLAB() 2020-12-07 15:03:35 +01:00
Sébastien Villemot 4e16ffcda2
Fortran MEX interface: minor fix for interface to dgemv 2020-10-21 18:17:41 +02:00
Sébastien Villemot ce5aa33a33
k-order DLL: no longer write journal file on-disk, unless options_.debug = true
Closes: #1735
2020-10-15 17:19:30 +02:00
Stéphane Adjemian (Charybdis) e690c5de5a
Merge Enterprise/block_trust_region into enterprise. 2020-09-24 16:05:55 +02:00
Stéphane Adjemian (Charybdis) 17e6421ea3
Merged master into enterprise.
Fixed conflict in
 - doc/manual/source/running-dynare.rst
2020-09-23 15:28:19 +02:00
Sébastien Villemot 73253a0620
Bytecode + Block decomposition: fix crash with purely forward variables
After simulating a block containing purely forward variables (thus of type
“evaluate backward”), the it_ variable of the evaluator would be left in an
inconsistent state (typically 0, which means that taking the value of a lagged
variable would lead to an invalid read).

By the way, fix a symmetric problem for backward blocks (which could
potentially create a invalid read for purely backward models).

Ref. #1727
2020-09-22 16:45:44 +02:00
Sébastien Villemot 8803bc1479
Bytecode: minor improvement to debugging information 2020-09-22 16:42:33 +02:00
Sébastien Villemot 865ab47fa9
Provide block_trust_region MEX under solve_algo 13 and 14
- block trust region solver now available under solve_algo=13
  It is essentially the same as solve_algo=4, except that Jacobian by finite
  difference is not handled. A test file is added for that case
- block trust region solver with shortcut for equations that can be evaluated
  is now available under solve_algo=14 (in replacement of the pure-MATLAB solver)

Closes: Enterprise/dynare#3
2020-09-18 18:01:56 +02:00
Sébastien Villemot 7e21bf2a10
Block trust region MEX: use MATLAB’s dmperm for the Dulmage-Mendelsohn decomposition
It turns out that MATLAB’s implementation is significantly faster than my own
Fortran implementation.
2020-09-18 17:55:58 +02:00
Sébastien Villemot 35a162c6a6
Block trust region MEX: fix memory leak in MATLAB function closure 2020-09-18 17:55:58 +02:00
Sébastien Villemot adf1fdb009
Block trust region MEX: add safety check for squareness of blocks 2020-09-18 17:55:58 +02:00
Sébastien Villemot 9430b4e9ca
Block trust region MEX: add debugging information 2020-09-18 17:55:57 +02:00
Stéphane Adjemian (Odysseus) 248ad18846 Merge remote-tracking branch 'Dynare/master' into enterprise
Fixed conflicts in:

 - .gitlab-ci.yml
 - matlab/dynare_config.m
 - matlab/dynare_solve.m
 - matlab/initvalf.m
 - matlab/perfect-foresight-models/make_ex_.m
 - matlab/perfect-foresight-models/perfect_foresight_setup.m
 - mex/build/matlab/Makefile.am
 - mex/build/matlab/configure.ac
 - mex/build/octave/Makefile.am
 - mex/build/octave/configure.ac
 - mex/sources/Makefile.am
 - preprocessor
 - tests/Makefile.am
2020-09-17 14:53:32 +02:00
Sébastien Villemot f6c2471eef
New MEX for solving discrete Lyapunov equations with doubling algorithm
This is a Fortran 2008 rewrite of disclyap_fast.m.

Closes: #1737
2020-07-30 16:34:35 +02:00
Sébastien Villemot 3f53a94981
Add dpotrf to Fortran 2008 BLAS/LAPACK bindings 2020-07-30 16:34:35 +02:00
Sébastien Villemot ea18431230
Various improvements to mjdgges MEX 2020-07-30 16:34:33 +02:00
Sébastien Villemot f4a31a0d1f
Various improvements to Fortran 2008 interface to MATLAB MEX functions
— add interface for more functions (cell, logical, struct)
— add new mexPrintf wrapper that trims and prints a newline
— functions that take indices of type mwIndex now 1-based indices
— improve the wrapper for mxArrayToString so that it returns a character scalar
2020-07-30 14:45:50 +02:00
Sébastien Villemot 49b35be90a
Preprocessor: various improvements to the use_dll mode
In particular, higher order derivatives are now returned as sparse matrices by
the static/dynamic files, instead of 3-column matrices (which was inconsistent
with the M-file mode).
2020-06-23 19:38:49 +02:00
Sébastien Villemot 31a9a5e9ab
Bytecode MEX: various fixes to debug mode 2020-05-13 12:22:20 +02:00
Sébastien Villemot f4f296edd6
Preprocessor update
— various refactoring and bugfixes in block decomposition
— small bugfix for PAC models
2020-05-06 18:17:25 +02:00
Sébastien Villemot 6e0f104d7e
Bump minimal MATLAB version to R2014a
Ref. #1713
2020-04-07 16:32:32 +02:00
Sébastien Villemot 43ed7b2b69
Merge remote-tracking branch 'community/master' into enterprise 2020-03-27 16:28:41 +01:00
Sébastien Villemot fbfff18378
Preprocessor: various refactorings of block decomposition
Adapt bytecode MEX accordingly.
2020-03-20 18:51:37 +01:00
Sébastien Villemot 144bdf34ba
k-order MEX: fix crash on Octave when higher-order derivatives have numerical zero
In Octave, when some values given to the sparse() function are numerically
zero, then the nzmax of the generated sparse matrix is shrinked accordingly;
while under MATLAB, the nzmax is the length of the vector of values, zeros
included.

The check at the top of
DynamicModelMFile::unpackSparseMatrixAndCopyIntoTwoDMatData() would then fail
under Octave if some higher-derivatives had an element which is symbolically
non-zero but numerically zero.

We therefore relax the check, and accordingly adapt the code that handles
numerical zeros.

This bug was uncovered by tests/pruning/AnSchorfheide_pruned_state_space.mod,
which was failing under Octave.
2020-02-18 12:18:39 +01:00
Sébastien Villemot ae3f150c99
MS-SBVAR MEX: various simplifications and modernizations 2020-02-10 16:25:03 +01:00
Sébastien Villemot 5f9b9db31e
Build system: add missing Fortran 2008 files to source tarball 2020-01-16 16:54:47 +01:00
Sébastien Villemot 7e770f69e7
Remove workaround for errors in MEX files
Because at some point throwing exceptions from MEX files (with mexErrMsgTxt())
was not working under Windows 64-bit, we had designed a workaround to avoid
using exceptions.

Most MEX files were returning an error code as their first (or sometimes last)
argument, and that code would have to be checked from the MATLAB code.

Since this workaround is no longer needed, this commit removes it. As a
consequence, the interface of many MEX files is modified.

For some background, see https://www.dynare.org/pipermail/dev/2010-September/000895.html
2020-01-10 18:33:11 +01:00
Sébastien Villemot 89dc67eb46
Convert mjdgges MEX to Fortran 2008 2020-01-09 09:23:07 +01:00
Sébastien Villemot c0c95e1ceb
Add Fortran 2008 interface for a subset of BLAS/LAPACK functions 2020-01-06 18:29:47 +01:00
Sébastien Villemot ce9eca366d
Add Fortran 2008 interface for a subset of MEX functions 2020-01-06 18:29:47 +01:00
Sébastien Villemot b901b7af86
Global reindentation of MEX sources 2019-12-20 16:30:24 +01:00
Sébastien Villemot 996bdd6c64 New local_state_space_iteration_k MEX, for nonlinear filters at k-order
It applies the approximated policy function to a set of particles, using
Dynare++ routines.

There is support for parallelization, using Dynare++ multithreading
model (itself based on C++11 threads; we don’t use OpenMP because it is
incompatible with MKL). For the time being, default to a single thread. This
should be later refined through empirical testing.
2019-12-20 11:31:56 +01:00
Sébastien Villemot 6a26926892
Add new block_trust_region MEX
This MEX solves nonlinear systems of equations using a trust region algorithm.
The problem is subdivided in smaller problems by doing a block
triangularisation of the Jacobian at the guess value, using the
Dulmage-Mendelsohn algorithm.

The interface of the MEX is simply:

  [x, info] = block_trust_region(f, guess_value);

Where f is either a function handle or a string designating a function.
f must take one argument (the evaluation point), and return either one or two
arguments (the residuals and, optionally, the Jacobian).

On success, info=0; on failure, info=1.
2019-12-03 16:17:16 +01:00
Sébastien Villemot 93bd817ccb
Add Fortran 2008 interface for a subset of BLAS/LAPACK functions 2019-12-03 16:17:12 +01:00
Sébastien Villemot ba466d22c8
Add Fortran 2008 interface for a subset of MEX functions 2019-12-03 16:17:08 +01:00
Sébastien Villemot 9e222734a8
Bytecode: fix logic in routine that substracts two sparse matrices
The logic of the dynSparseMatrix::Sparse_substract_SA_SB() routine was
incorrect.

In some cases, it would read past the last nonzero elements of the A matrix,
and consequently write past the number of allocated nonzero elements of the C
matrix.

This would lead to crashes and, probably, to wrong results under certain
circumstances.

Closes: #1652
2019-11-27 16:57:47 +01:00
Sébastien Villemot 42f172dec3
perfect_foresight_problem MEX: optimization for linear models
When the model is linear, there is no need to reevaluate the Jacobian for each
time period, since it is invariant.

Closes: #1662
2019-11-14 14:45:10 +01:00
Houtan Bastani afcdf46e80
capitalize Cepremap and Matlab, uncapitalize DYNARE 2019-10-02 14:09:21 +02:00
Sébastien Villemot 6ff7d4c56c
C++17: use structured bindings instead of std::tie 2019-09-11 16:06:35 +02:00
Houtan Bastani 1501032a3f
replace use of old-style casts 2019-07-30 15:15:23 -04:00
Sébastien Villemot 4030169db9
k_order_perturbation MEX: number of threads is now configurable 2019-07-09 17:33:14 +02:00
Sébastien Villemot 5b6c3bb452
k_order_perturbation MEX: small simplification in handling of NameLists 2019-07-09 17:33:14 +02:00