Beautified MEX source code
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3251 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
502e3e1df8
commit
f3549b4c64
|
@ -40,7 +40,6 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#define pow_ pow
|
||||
|
||||
typedef vector<pair<Tags, void * > >::const_iterator it_code_type;
|
||||
|
@ -80,5 +79,4 @@ class Interpreter : SparseMatrix
|
|||
bool compute_blocks(string file_name, string bin_basename, bool steady_state, bool evaluate);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,7 +46,8 @@ Mem_Mngr::init_Mem()
|
|||
NZE_Mem_Allocated.clear();
|
||||
}
|
||||
|
||||
void Mem_Mngr::fixe_file_name(string filename_arg)
|
||||
void
|
||||
Mem_Mngr::fixe_file_name(string filename_arg)
|
||||
{
|
||||
filename = filename_arg;
|
||||
}
|
||||
|
@ -98,7 +99,6 @@ Mem_Mngr::mxMalloc_NZE()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Mem_Mngr::mxFree_NZE(void *pos)
|
||||
{
|
||||
|
@ -113,7 +113,6 @@ Mem_Mngr::mxFree_NZE(void* pos)
|
|||
Chunk_Stack.push_back((NonZeroElem *) pos);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Mem_Mngr::Free_All()
|
||||
{
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#ifndef MEM_MNGR_HH_INCLUDED
|
||||
#define MEM_MNGR_HH_INCLUDED
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#ifndef DEBUG_EX
|
||||
|
|
|
@ -37,25 +37,29 @@ using namespace std;
|
|||
extern unsigned long _nan[2];
|
||||
extern double NAN;
|
||||
|
||||
inline bool isnan(double value)
|
||||
inline bool
|
||||
isnan(double value)
|
||||
{
|
||||
return _isnan(value);
|
||||
}
|
||||
|
||||
inline bool isinf(double value)
|
||||
inline bool
|
||||
isinf(double value)
|
||||
{
|
||||
return (std::numeric_limits<double>::has_infinity &&
|
||||
value == std::numeric_limits<double>::infinity());
|
||||
return (std::numeric_limits<double>::has_infinity
|
||||
&& value == std::numeric_limits<double>::infinity());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T asinh(T x)
|
||||
inline T
|
||||
asinh(T x)
|
||||
{
|
||||
return log(x+sqrt(x*x+1));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T acosh(T x)
|
||||
inline T
|
||||
acosh(T x)
|
||||
{
|
||||
if (!(x >= 1.0))
|
||||
return sqrt(-1.0);
|
||||
|
@ -63,7 +67,8 @@ inline T acosh(T x)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
inline T atanh(T x)
|
||||
inline T
|
||||
atanh(T x)
|
||||
{
|
||||
if (!(x > -1.0 && x < 1.0))
|
||||
return sqrt(-1.0);
|
||||
|
@ -90,7 +95,6 @@ const double eps=1e-10;
|
|||
const double very_big = 1e24;
|
||||
const int alt_symbolic_count_max = 1;
|
||||
|
||||
|
||||
class SparseMatrix
|
||||
{
|
||||
public:
|
||||
|
@ -180,6 +184,4 @@ protected:
|
|||
bool error_not_printed;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include "Mem_Mngr.hh"
|
||||
|
||||
|
||||
#ifdef DEBUG_EX
|
||||
|
||||
using namespace std;
|
||||
|
@ -45,7 +44,6 @@ Get_Argument(const char *argv)
|
|||
return f;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
|
@ -315,7 +313,6 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
|||
if (status != 0)
|
||||
mexWarnMsgTxt("Not enough space. Filename is truncated.");
|
||||
|
||||
|
||||
int size_of_direction = col_y*row_y*sizeof(double);
|
||||
double *y = (double *) mxMalloc(size_of_direction);
|
||||
double *ya = (double *) mxMalloc(size_of_direction);
|
||||
|
@ -332,7 +329,6 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
|||
int y_size = row_y;
|
||||
int nb_row_x = row_x;
|
||||
|
||||
|
||||
clock_t t0 = clock();
|
||||
Interpreter interprete(params, y, ya, x, steady_yd, steady_xd, direction, y_size, nb_row_x, nb_row_xd, periods, y_kmin, y_kmax, maxit_, solve_tolf, size_of_direction, slowc, y_decal, markowitz_c, file_name, minimal_solving_periods);
|
||||
string f(fname);
|
||||
|
|
|
@ -42,7 +42,6 @@ mxRealloc(void* to_extend, int amount)
|
|||
return realloc(to_extend, amount);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mexEvalString(const string str)
|
||||
{
|
||||
|
|
|
@ -34,4 +34,3 @@ global M_ oo_ options_;
|
|||
fprintf(fid,'%6.20f\n',oo_.steady_state);
|
||||
fprintf(fid,'%6.20f\n',oo_.exo_steady_state);
|
||||
fclose(fid);
|
||||
|
|
@ -27,8 +27,8 @@
|
|||
* <model>_dynamic () function
|
||||
**************************************/
|
||||
DynamicModelDLL::DynamicModelDLL(const string &modName, const int y_length, const int j_cols,
|
||||
const int n_max_lag, const int n_exog, const string &sExt) throw (DynareException)
|
||||
: length(y_length), jcols(j_cols), nMax_lag(n_max_lag), nExog(n_exog)
|
||||
const int n_max_lag, const int n_exog, const string &sExt) throw (DynareException) :
|
||||
length(y_length), jcols(j_cols), nMax_lag(n_max_lag), nExog(n_exog)
|
||||
{
|
||||
string fName;
|
||||
#if !defined(__CYGWIN32__) && !defined(_WIN32)
|
||||
|
|
|
@ -39,8 +39,8 @@ KordpDynare::KordpDynare(const char **endo, int num_endo,
|
|||
int npred, int nforw, int nboth, const int jcols, const Vector *nnzd,
|
||||
const int nsteps, int norder, //const char* modName,
|
||||
Journal &jr, DynamicModelDLL &dynamicDLL, double sstol,
|
||||
const vector<int> *var_order, const TwoDMatrix *llincidence, double criterium) throw (TLException)
|
||||
: nStat(nstat), nBoth(nboth), nPred(npred), nForw(nforw), nExog(nexog), nPar(npar),
|
||||
const vector<int> *var_order, const TwoDMatrix *llincidence, double criterium) throw (TLException) :
|
||||
nStat(nstat), nBoth(nboth), nPred(npred), nForw(nforw), nExog(nexog), nPar(npar),
|
||||
nYs(npred + nboth), nYss(nboth + nforw), nY(num_endo), nJcols(jcols), NNZD(nnzd), nSteps(nsteps),
|
||||
nOrder(norder), journal(jr), dynamicDLL(dynamicDLL), ySteady(ysteady), vCov(vcov), params(inParams),
|
||||
md(1), dnl(NULL), denl(NULL), dsnl(NULL), ss_tol(sstol), varOrder(var_order),
|
||||
|
@ -60,8 +60,8 @@ KordpDynare::KordpDynare(const char **endo, int num_endo,
|
|||
}
|
||||
}
|
||||
|
||||
KordpDynare::KordpDynare(const KordpDynare &dynare)
|
||||
: nStat(dynare.nStat), nBoth(dynare.nBoth), nPred(dynare.nPred),
|
||||
KordpDynare::KordpDynare(const KordpDynare &dynare) :
|
||||
nStat(dynare.nStat), nBoth(dynare.nBoth), nPred(dynare.nPred),
|
||||
nForw(dynare.nForw), nExog(dynare.nExog), nPar(dynare.nPar),
|
||||
nYs(dynare.nYs), nYss(dynare.nYss), nY(dynare.nY), nJcols(dynare.nJcols),
|
||||
NNZD(dynare.NNZD), nSteps(dynare.nSteps), nOrder(dynare.nOrder),
|
||||
|
|
|
@ -291,8 +291,8 @@ class KordpVectorFunction : public ogu::VectorFunction
|
|||
protected:
|
||||
KordpDynare &d;
|
||||
public:
|
||||
KordpVectorFunction(KordpDynare &dyn)
|
||||
: d(dyn)
|
||||
KordpVectorFunction(KordpDynare &dyn) :
|
||||
d(dyn)
|
||||
{
|
||||
}
|
||||
virtual ~KordpVectorFunction()
|
||||
|
|
|
@ -213,7 +213,6 @@ extern "C" {
|
|||
npar = (int) mxGetN(mxFldp);
|
||||
int nrows = (int) mxGetM(mxFldp);
|
||||
|
||||
|
||||
TwoDMatrix *llincidence = new TwoDMatrix(nrows, npar, dparams);
|
||||
if (npar != nEndo)
|
||||
mexErrMsgIdAndTxt("dynare:k_order_perturbation", "Incorrect length of lead lag incidences: ncol=%d != nEndo=%d.", npar, nEndo);
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
# include <omp.h>
|
||||
#endif
|
||||
|
||||
void full_A_times_kronecker_B_C(double *A, double *B, double *C, double *D,
|
||||
void
|
||||
full_A_times_kronecker_B_C(double *A, double *B, double *C, double *D,
|
||||
blas_int mA, blas_int nA, blas_int mB, blas_int nB, blas_int mC, blas_int nC)
|
||||
{
|
||||
#if USE_OMP
|
||||
|
@ -75,8 +76,8 @@ void full_A_times_kronecker_B_C(double *A, double *B, double *C, double *D,
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
void full_A_times_kronecker_B_B(double *A, double *B, double *D, blas_int mA, blas_int nA, blas_int mB, blas_int nB)
|
||||
void
|
||||
full_A_times_kronecker_B_B(double *A, double *B, double *D, blas_int mA, blas_int nA, blas_int mB, blas_int nB)
|
||||
{
|
||||
#if USE_OMP
|
||||
# pragma omp parallel for num_threads(atoi(getenv("DYNARE_NUM_THREADS")))
|
||||
|
@ -119,7 +120,8 @@ void full_A_times_kronecker_B_B(double *A, double *B, double *D, blas_int mA, bl
|
|||
#endif
|
||||
}
|
||||
|
||||
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
|
||||
void
|
||||
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// Check input and output:
|
||||
if ((nrhs > 3) || (nrhs < 2))
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
# include <omp.h>
|
||||
#endif
|
||||
|
||||
void sparse_hessian_times_B_kronecker_B(mwIndex *isparseA, mwIndex *jsparseA, double *vsparseA,
|
||||
void
|
||||
sparse_hessian_times_B_kronecker_B(mwIndex *isparseA, mwIndex *jsparseA, double *vsparseA,
|
||||
double *B, double *D, mwSize mA, mwSize nA, mwSize mB, mwSize nB)
|
||||
{
|
||||
/*
|
||||
|
@ -86,7 +87,8 @@ void sparse_hessian_times_B_kronecker_B(mwIndex *isparseA, mwIndex *jsparseA, do
|
|||
}
|
||||
}
|
||||
|
||||
void sparse_hessian_times_B_kronecker_C(mwIndex *isparseA, mwIndex *jsparseA, double *vsparseA,
|
||||
void
|
||||
sparse_hessian_times_B_kronecker_C(mwIndex *isparseA, mwIndex *jsparseA, double *vsparseA,
|
||||
double *B, double *C, double *D,
|
||||
mwSize mA, mwSize nA, mwSize mB, mwSize nB, mwSize mC, mwSize nC)
|
||||
{
|
||||
|
@ -135,7 +137,8 @@ void sparse_hessian_times_B_kronecker_C(mwIndex *isparseA, mwIndex *jsparseA, do
|
|||
}
|
||||
}
|
||||
|
||||
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
|
||||
void
|
||||
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
// Check input and output:
|
||||
if ((nrhs > 3) || (nrhs < 2))
|
||||
|
|
|
@ -30,7 +30,8 @@ my_criteria(const double *alphar, const double *alphai, const double *beta)
|
|||
return ((*alphar * *alphar + *alphai * *alphai) < criterium * *beta * *beta);
|
||||
}
|
||||
|
||||
void mjdgges(double *a, double *b, double *z, double *n, double *sdim, double *eval_r, double *eval_i, double *info)
|
||||
void
|
||||
mjdgges(double *a, double *b, double *z, double *n, double *sdim, double *eval_r, double *eval_i, double *info)
|
||||
{
|
||||
lapack_int i_n, i_info, i_sdim, one, lwork;
|
||||
double *alphar, *alphai, *beta, *work, *par, *pai, *pb, *per, *pei;
|
||||
|
@ -69,7 +70,8 @@ void mjdgges(double *a, double *b, double *z, double *n, double *sdim, double *e
|
|||
}
|
||||
|
||||
/* MATLAB interface */
|
||||
void mexFunction( int nlhs, mxArray *plhs[],
|
||||
void
|
||||
mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
|
||||
{
|
||||
|
@ -79,9 +81,12 @@ void mexFunction( int nlhs, mxArray *plhs[],
|
|||
|
||||
/* Check for proper number of arguments */
|
||||
|
||||
if (nrhs < 2 || nrhs > 3) {
|
||||
if (nrhs < 2 || nrhs > 3)
|
||||
{
|
||||
mexErrMsgTxt("MJDGGES: two or three input arguments are required.");
|
||||
} else if (nlhs > 6) {
|
||||
}
|
||||
else if (nlhs > 6)
|
||||
{
|
||||
mexErrMsgTxt("MJDGGES: too many output arguments.");
|
||||
}
|
||||
|
||||
|
@ -91,9 +96,10 @@ void mexFunction( int nlhs, mxArray *plhs[],
|
|||
n1 = mxGetN(prhs[0]);
|
||||
m2 = mxGetM(prhs[1]);
|
||||
n2 = mxGetN(prhs[1]);
|
||||
if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
|
||||
!mxIsDouble(prhs[1]) || mxIsComplex(prhs[1]) ||
|
||||
(m1 != n1) || (m2!= n1) || (m2 != n2)) {
|
||||
if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0])
|
||||
|| !mxIsDouble(prhs[1]) || mxIsComplex(prhs[1])
|
||||
|| (m1 != n1) || (m2 != n1) || (m2 != n2))
|
||||
{
|
||||
mexErrMsgTxt("MJDGGES requires two square real matrices of the same dimension.");
|
||||
}
|
||||
|
||||
|
@ -136,7 +142,6 @@ void mexFunction( int nlhs, mxArray *plhs[],
|
|||
/* Do the actual computations in a subroutine */
|
||||
mjdgges(s, t, z, &n, sdim, eval_r, eval_i, info);
|
||||
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue