— FCFLAGS needs to contain the compilation flags used when compiling Octave,
otherwise it fails at configure stage when looking for gfortran
— Explicitly add -L$OCTLIBDIR, because with Octave 5 it is no longer there, and
on Fedora the Octave libraries are no in the default linker search path
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
- 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
— 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
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).
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.
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
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.
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.
The changes in 8065e9d439 were not working as
intended, because AC_CHECK_PROG expect values and not actions. Hence
AC_MSG_ERROR was not properly executed.
By the way, simplify some test conditions using && instead of if/then/fi
blocks.
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
In particular, if either MATLAB or Octave is missing, one needs to pass either
--disable-matlab or --disable-octave.
Moreover, several new configure flags have been introduced for disabling some
components:
--disable-doc
--disable-dynare++
--disable-mex-dynare++
--disable-mex-ms-sbvar
--disable-mex-kalman-steady-state
The MEX files are built out-of-tree (because we want to do them in parallel).
This would create a potential race condition if several builds want to create
the symlinks under mex/matlab/ or mex/octave/.
The solution is to disable those symlinks for out-of-tree builds.
The scripts are based the former “dynare-build” project. They have been
overhauled and simplified.
Building a Windows package (both installer and zip archive) is as easy as
running “make -C windows” (provided the right Debian packages are installed,
use the “windows/install-packages.sh” script for that purpose).
The layout of MEX files for Octave in the package has been
changed (mex/octave/win32/ and mex/octave/win64/ instead of mex/octave32/ and
mex/octave/), for consistency with MATLAB MEX.
It constructs the stacked residuals and jacobian of the perfect foresight
problem.
It is an almost perfect replacement for the perfect_foresight_problem.m
routine, while being much more efficient.
Note however that the DLL never return complex numbers (it instead puts NaNs at
the place where there would have been complex). This may create problems for
some MOD files; the algorithms will need to be adapted to use a more
line-search method.
Various modernizations and simplifications.
Also remove a workaround for a LAPACK bug in DGGES (the VSL argument was
apparently referenced even though JOBVSL="N"). Hopefully the bug has been fixed
everywhere now.
Previously there were GeneralMatrix::numRows() and TwoDMatrix::nrows() for doing
the same thing (and same for columns and Const versions).
Merge these two into GeneralMatrix::nrows().
Note that I removed several #define whose purpose was to avoid typing "typename
ctraits<t>::…". Even though this tends to complicates the code, this is
probably safer, especially since the #define was capturing a free variable (t).
As a consequence, the singleton implementation has to be made thread-safe.
Also implement the singleton pattern using a namespace, rather than a static
instance.
There were two implementations of integer exponentiation. Merge them into a new
file under utils/cc/.
By the way, optimize it using exponentiation by squaring.
We now use a initializer list constructor for creating symmetries of the form
$y^n$, $y^n u^m$, $y^nu^m\sigma^k$.
The constructor taking a single integer is used to initialize a symmetry of a
given length.
Similar changes are made to IntSequence.
This behavior is similar to std::vector.
On Windows, this means that a POSIX threads implementation is no longer needed,
since C++11 threads are implemented using native Windows threads.
On GNU/Linux and macOS, POSIX threads are still used under the hood.
A new m4 macro (AX_CXX11_THREAD) is used to add the proper compilation
flags (instead of AX_PTHREAD).
- Remove the GeneralMatrix(const ConstVector &) constructor, since it is hides
a memory allocation (copying the ConstVector into a fresh Vector). This
helped detecting and fixing several unneeded memory allocations. Some other
memory allocations are now more visible (with an explicit Vector{}
constructor).
- Add checks in GeneralMatrix(Vector, …) and ConstGeneralMatrix(ConstVector, …)
constructors for verifying that the {Const,}Vector has unit-stride (this was
an implicit assumption so far) and is large enough for storing rows*cols
elements.
- Add GeneralMatrix::operator=(const ConstGeneralMatrix &).
- Delete ConstGeneralMatrix::operator=().
- these classes now encapsulate a std::shared_ptr<{const, }double>, so that
they do not perform memory management, and several {Const,}Vector instances
can transparently share the same underlying data
- make converting constructor from ConstVector to Vector explicit, since that
entails memory allocation (but the reverse conversion is almost costless, so
keep it implicit); do the same for GeneralMatrix/ConstGeneralMatrix,
TwoDMatrix/ConstTwoDMatrix
- remove the constructors that were extracting a row/column from a matrix, and
replace them by getRow() and getCol() methods on {Const,}GeneralMatrix
- rename and change the API of the complex version Vector::add(), so that it is
explicit that it deals with complex numbers
- add constructors that take a MATLAB mxArray
The criterium was previously incorrectly applied to the square absolute value of
eigenvalues. Rather apply it to the absolute value itself (as done in
mjdgges.m and the AIM solver).
Closes#1632
- Use the -static flag when linking Dynare++, so that shipping libquadmath and
libgcc DLL in the installer is no longer needed.
- Use AM_CXXFLAGS and AM_LDFLAGS variables for changing flags, since CXXFLAGS
and LDFLAGS are user variables. Also, this avoids passing these flags down to
configure scripts in subdirectories.
- Check for the SZIP library in the configure test for the MatIO, this is
needed under MSYS2.
- Statically link MatIO and GSL in MEX files for MATLAB, this is needed under
MSYS2.
The bug would show at order 3 when the last output argument (derivs) is not
requested (in practice every 3rd order solution without pruning). The DLL would
still attempt to write into it, causing an invalid memory access.
- replaces maximum_endo_(lead|lag) by maximum_(lead|lag) to determine the maximum number of lead and lag in deterministic simulation
- allows to use bytecode in solve_perfect_foresight_model.m
- Adds model information in bytecode
In the case where a 2nd/3rd derivative is symbolically not zero but numerically
zero at the evaluation point, the last lines of the g2/g3 matrices (in
KordpDynare::calcDerivativesAtSteady()) where uninitialized (these matrices
store the sparse hessian/3rd-deriv in coordinate list form, i.e. with 3 columns
and as many rows as non-zero elements). When reconstructing the dense
hessian/3rd-deriv matrix out of g2/g3, this would result in invalid memory
accesses.
- no longer use OCTAVE_QUIT in MEX files; this seems now only possible in
oct-files. (Ref #304)
- do not build linsolve.oct on Octave >= 3.8, it is available natively.
- do not add strjoin.m to the patch on Octave >= 3.8, it is available natively.
- default_save_options has been renamed save_default_options.