Global reindentation of MEX sources

time-shift
Sébastien Villemot 2019-12-20 14:50:19 +01:00
parent 22ab507c6c
commit b901b7af86
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
25 changed files with 432 additions and 412 deletions

View File

@ -466,7 +466,7 @@ BlockKalmanFilter::block_kalman_filter(int nlhs, mxArray *plhs[])
int j1 = j - pure_obs;
int j1_n_state = j1 * n_state - pure_obs;
for (int k = pure_obs; k < i_nz_state_var[i]; k++)
tmp[i + j1 * n ] += T[i + k * n] * P[k + j1_n_state];
tmp[i + j1 * n] += T[i + k * n] * P[k + j1_n_state];
}
std::fill_n(P, 0, n * n);

View File

@ -152,7 +152,7 @@ using namespace std;
const int NO_ERROR_ON_EXIT = 0;
const int ERROR_ON_EXIT = 1;
typedef vector<pair<Tags, void * > > code_liste_type;
typedef vector<pair<Tags, void * >> code_liste_type;
typedef code_liste_type::const_iterator it_code_type;
class GeneralExceptionHandling
@ -271,7 +271,7 @@ struct s_plan
{
string var, exo;
int var_num, exo_num;
vector<pair<int, double> > per_value;
vector<pair<int, double>> per_value;
vector<double> value;
};
@ -310,7 +310,7 @@ public:
vector<mxArray *> jacobian_block, jacobian_other_endo_block, jacobian_exo_block, jacobian_det_exo_block;
map<unsigned int, double> TEF;
map<pair<unsigned int, unsigned int>, double > TEFD;
map<pair<unsigned int, pair<unsigned int, unsigned int> >, double > TEFDD;
map<pair<unsigned int, pair<unsigned int, unsigned int>>, double > TEFDD;
ExpressionType EQN_type;
it_code_type it_code_expr;
@ -319,7 +319,7 @@ public:
size_t /*unsigned int*/ endo_name_length, exo_name_length, param_name_length;
unsigned int EQN_equation, EQN_block, EQN_block_number;
unsigned int EQN_dvar1, EQN_dvar2, EQN_dvar3;
vector<pair<string, pair<SymbolType, unsigned int> > > Variable_list;
vector<pair<string, pair<SymbolType, unsigned int>>> Variable_list;
inline
ErrorMsg()
@ -2134,7 +2134,7 @@ public:
#ifdef DEBUG
double rr = Stackf.top();
mexPrintf("rr=%f\n", rr);
map<pair<unsigned int, pair<unsigned int, unsigned int> >, double>::const_iterator it = TEFDD.find(make_pair(indx, make_pair(row-1, col-1)));
map<pair<unsigned int, pair<unsigned int, unsigned int>>, double>::const_iterator it = TEFDD.find(make_pair(indx, make_pair(row-1, col-1)));
mexPrintf("FSTP TEFDD[make_pair(indx, make_pair(row, col))]=%f done\n", it->second);
mexEvalString("drawnow;");
#endif
@ -2157,13 +2157,13 @@ public:
#ifdef DEBUG
mexPrintf("FLDTEFD\n");
mexPrintf("indx=%d Stack.size()=%d\n", indx, Stack.size());
map<pair<unsigned int, pair<unsigned int, unsigned int> >, double>::const_iterator it = TEFDD.find(make_pair(indx, make_pair(row-1, col-1)));
map<pair<unsigned int, pair<unsigned int, unsigned int>>, double>::const_iterator it = TEFDD.find(make_pair(indx, make_pair(row-1, col-1)));
mexPrintf("FLD TEFD[make_pair(indx, make_pair(row, col))]=%f done\n", it->second);
mexEvalString("drawnow;");
#endif
if (compute)
{
map<pair<unsigned int, pair<unsigned int, unsigned int> >, double>::const_iterator it = TEFDD.find(make_pair(indx, make_pair(row-1, col-1)));
map<pair<unsigned int, pair<unsigned int, unsigned int>>, double>::const_iterator it = TEFDD.find(make_pair(indx, make_pair(row-1, col-1)));
Stackf.push(it->second);
}
tmp_out.str("");

View File

@ -921,9 +921,9 @@ Interpreter::extended_path(string file_name, string bin_basename, bool evaluate,
MainLoop(bin_basename, code, evaluate, block, true, true, sconstrained_extended_path, vector_table_conditional_local);
for (int j = 0; j < y_size; j++)
{
y_save[j + (t + y_kmin) * y_size] = y[ j + (y_kmin) * y_size];
y_save[j + (t + y_kmin) * y_size] = y[j + y_kmin * y_size];
if (y_kmin > 0)
y[j ] = y[ j + (y_kmin) * y_size];
y[j] = y[j + y_kmin * y_size];
}
for (int j = 0; j < col_x; j++)
{

View File

@ -49,39 +49,39 @@ t_umfpack_dl_free_numeric umfpack_dl_free_numeric;
typedef void (*t_umfpack_dl_free_symbolic)(void **Symbolic);
t_umfpack_dl_free_symbolic umfpack_dl_free_symbolic;
typedef int64_t (*t_umfpack_dl_solve)(int64_t sys,
const int64_t Ap [],
const int64_t Ai [],
const double Ax [],
double X [],
const double B [],
const int64_t Ap[],
const int64_t Ai[],
const double Ax[],
double X[],
const double B[],
void *Numeric,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]);
const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]);
t_umfpack_dl_solve umfpack_dl_solve;
typedef int64_t (*t_umfpack_dl_numeric)(const int64_t Ap [],
const int64_t Ai [],
const double Ax [],
typedef int64_t (*t_umfpack_dl_numeric)(const int64_t Ap[],
const int64_t Ai[],
const double Ax[],
void *Symbolic,
void **Numeric,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]);
const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]);
t_umfpack_dl_numeric umfpack_dl_numeric;
typedef int64_t (*t_umfpack_dl_symbolic)(int64_t n_row,
int64_t n_col,
const int64_t Ap [],
const int64_t Ai [],
const double Ax [],
const int64_t Ap[],
const int64_t Ai[],
const double Ax[],
void **Symbolic,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]);
const double Control[UMFPACK_CONTROL],
double Info[UMFPACK_INFO]);
t_umfpack_dl_symbolic umfpack_dl_symbolic;
typedef void (*t_umfpack_dl_report_info)(const double Control [UMFPACK_CONTROL],
const double Info [UMFPACK_INFO]);
typedef void (*t_umfpack_dl_report_info)(const double Control[UMFPACK_CONTROL],
const double Info[UMFPACK_INFO]);
t_umfpack_dl_report_info umfpack_dl_report_info;
typedef void (*t_umfpack_dl_report_status)(const double Control [UMFPACK_CONTROL],
typedef void (*t_umfpack_dl_report_status)(const double Control[UMFPACK_CONTROL],
int64_t status);
t_umfpack_dl_report_status umfpack_dl_report_status;
typedef void (*t_umfpack_dl_defaults)(double Control [UMFPACK_CONTROL]);
typedef void (*t_umfpack_dl_defaults)(double Control[UMFPACK_CONTROL]);
t_umfpack_dl_defaults umfpack_dl_defaults;
#endif
@ -796,7 +796,7 @@ dynSparseMatrix::Init_Matlab_Sparse_Simple(int Size, map<pair<pair<int, int>, in
var = it4->first.first.first;
if (var != last_var)
{
Aj[1+last_var ] = NZE;
Aj[1+last_var] = NZE;
last_var = var;
}
eq = it4->first.second;
@ -894,7 +894,7 @@ dynSparseMatrix::Init_UMFPACK_Sparse_Simple(int Size, map<pair<pair<int, int>, i
ya[eq+it_*y_size] = y[eq+it_*y_size];
}
#ifdef DEBUG
unsigned int max_nze = prior_nz;//mxGetNzmax(A_m);
unsigned int max_nze = prior_nz; //mxGetNzmax(A_m);
#endif
unsigned int NZE = 0;
int last_var = 0;
@ -918,7 +918,7 @@ dynSparseMatrix::Init_UMFPACK_Sparse_Simple(int Size, map<pair<pair<int, int>, i
var = it4->first.first.first;
if (var != last_var)
{
(*Ap)[1+last_var ] = NZE;
(*Ap)[1+last_var] = NZE;
last_var = var;
}
eq = it4->first.second;
@ -980,11 +980,11 @@ dynSparseMatrix::find_exo_num(vector<s_plan> sconstrained_extended_path, int val
}
int
dynSparseMatrix::find_int_date(vector<pair<int, double> > per_value, int value)
dynSparseMatrix::find_int_date(vector<pair<int, double>> per_value, int value)
{
int res = -1;
int i = 0;
for (vector<pair<int, double> >::iterator it = per_value.begin(); it != per_value.end(); it++, i++)
for (vector<pair<int, double>>::iterator it = per_value.begin(); it != per_value.end(); it++, i++)
if (it->first == value)
{
res = i;
@ -1369,7 +1369,7 @@ dynSparseMatrix::Init_CUDA_Sparse_Simple(int Size, map<pair<pair<int, int>, int>
var = it4->first.first.first;
if (var != last_var)
{
(*Ap)[1+last_var ] = NZE;
(*Ap)[1+last_var] = NZE;
last_var = var;
}
eq = it4->first.second;
@ -1509,7 +1509,7 @@ dynSparseMatrix::Init_CUDA_Sparse(int periods, int y_kmin, int y_kmax, int Size,
# endif
Host_Ap[1+last_eq + t * Size] = NZE;
if (preconditioner == 3 && t == 0)
Host_Ap_tild[1+last_eq ] = NZE_tild;
Host_Ap_tild[1+last_eq] = NZE_tild;
last_eq = eq;
}
var = it4->first.second+Size*t;
@ -3133,7 +3133,7 @@ dynSparseMatrix::Solve_Matlab_Relaxation(mxArray *A_m, mxArray *b_m, unsigned in
while (A3_var < Size)
A3_j[++A3_var] = A3_nze;
mxArray *d1 = NULL;
vector<pair<mxArray *, mxArray *> > triangular_form;
vector<pair<mxArray *, mxArray *>> triangular_form;
double sumc = 0, C_sumc = 1000;
mxArray *B1_inv = NULL;
mxArray *B1_inv_t = NULL;
@ -3333,7 +3333,7 @@ dynSparseMatrix::Solve_LU_UMFPack(SuiteSparse_long *Ap, SuiteSparse_long *Ai, do
{
SuiteSparse_long status, sys = 0;
#ifndef _MSC_VER
double Control [UMFPACK_CONTROL], Info [UMFPACK_INFO], res [n];
double Control[UMFPACK_CONTROL], Info[UMFPACK_INFO], res[n];
#else
double *Control, *Info, *res;
Control = (double *) mxMalloc(UMFPACK_CONTROL * sizeof(double));
@ -3345,7 +3345,7 @@ dynSparseMatrix::Solve_LU_UMFPack(SuiteSparse_long *Ap, SuiteSparse_long *Ai, do
#endif
umfpack_dl_defaults(Control);
Control [UMFPACK_PRL] = 5;
Control[UMFPACK_PRL] = 5;
status = 0;
if (iter == 0)
{
@ -3400,7 +3400,7 @@ dynSparseMatrix::Solve_LU_UMFPack(SuiteSparse_long *Ap, SuiteSparse_long *Ai, do
else
{
int eq = index_vara[i+Size*(y_kmin)];
double yy = -(res[i ] + y[eq]);
double yy = -(res[i] + y[eq]);
direction[eq] = yy;
y[eq] += slowc_l * yy;
}
@ -3461,7 +3461,7 @@ dynSparseMatrix::Solve_LU_UMFPack(SuiteSparse_long *Ap, SuiteSparse_long *Ai, do
{
SuiteSparse_long status, sys = 0;
#ifndef _MSC_VER
double Control [UMFPACK_CONTROL], Info [UMFPACK_INFO], res [n];
double Control[UMFPACK_CONTROL], Info[UMFPACK_INFO], res[n];
#else
double *Control, *Info, *res;
Control = (double *) mxMalloc(UMFPACK_CONTROL * sizeof(double));
@ -3473,7 +3473,7 @@ dynSparseMatrix::Solve_LU_UMFPack(SuiteSparse_long *Ap, SuiteSparse_long *Ai, do
#endif
umfpack_dl_defaults(Control);
Control [UMFPACK_PRL] = 5;
Control[UMFPACK_PRL] = 5;
status = 0;
if (iter == 0)
{
@ -3547,7 +3547,7 @@ dynSparseMatrix::Solve_LU_UMFPack(mxArray *A_m, mxArray *b_m, int Size, double s
double *B = mxGetPr(b_m);
SuiteSparse_long status, sys = 0;
#ifndef _MSC_VER
double Control [UMFPACK_CONTROL], Info [UMFPACK_INFO], res [n];
double Control[UMFPACK_CONTROL], Info[UMFPACK_INFO], res[n];
#else
double *Control, *Info, *res;
Control = (double *) mxMalloc(UMFPACK_CONTROL * sizeof(double));
@ -3627,7 +3627,7 @@ printM(int n, double *Ax, int *Ap, int *Ai, cusparseMatDescr_t descrA, cusparse
void
dynSparseMatrix::Solve_CUDA_BiCGStab_Free(double *tmp_vect_host, double *p, double *r, double *v, double *s, double *t, double *y_, double *z, double *tmp_,
int *Ai, double *Ax, int *Ap, double *x0, double *b, double *A_tild, int *A_tild_i, int *A_tild_p/*, double* Lx, int* Li, int* Lp,
int *Ai, double *Ax, int *Ap, double *x0, double *b, double *A_tild, int *A_tild_i, int *A_tild_p /*, double* Lx, int* Li, int* Lp,
double* Ux, int* Ui, int* Up, int* device_n*/, cusparseSolveAnalysisInfo_t infoL, cusparseSolveAnalysisInfo_t infoU,
cusparseMatDescr_t descrL, cusparseMatDescr_t descrU, int preconditioner)
{
@ -3756,7 +3756,7 @@ dynSparseMatrix::Solve_CUDA_BiCGStab(int *Ap, int *Ai, double *Ax, int *Ap_tild,
{
cusparseSolveAnalysisInfo_t info, infoL, infoU;
cusparseMatDescr_t descrL, descrU;
const double tol = 1.0e-6;//1.0e-6;
const double tol = 1.0e-6; //1.0e-6;
const double eps = 1.0e-16;
double *p, *r, *r0, *v, *s, *t, *y_, *z, *tmp_;
int *A_tild_i, *A_tild_p;
@ -5129,7 +5129,7 @@ dynSparseMatrix::Singular_display(int block, int Size)
{
int k = first->u_index;
int jj = first->r_index;
pind[ii * Size + jj ] = u[k];
pind[ii * Size + jj] = u[k];
first = first->NZE_C_N;
}
}
@ -6458,7 +6458,6 @@ dynSparseMatrix::solve_linear(const int block_num, const int y_size, const int y
void
dynSparseMatrix::solve_non_linear(const int block_num, const int y_size, const int y_kmin, const int y_kmax, const int size)
{
max_res_idx = 0;
bool cvg = false;

View File

@ -122,7 +122,7 @@ public:
double g0, gp0, glambda2;
int try_at_iteration;
int find_exo_num(vector<s_plan> sconstrained_extended_path, int value);
int find_int_date(vector<pair<int, double> > per_value, int value);
int find_int_date(vector<pair<int, double>> per_value, int value);
private:
void Init_GE(int periods, int y_kmin, int y_kmax, int Size, map<pair<pair<int, int>, int>, int> &IM);

View File

@ -704,7 +704,7 @@ main(int nrhs, const char *prhs[])
string tmp = "Can not allocated memory to store the date_str in the extended path descriptor";
DYN_MEX_FUNC_ERR_MSG_TXT(tmp.c_str());
}
dates.push_back(string(buf));//string(Dates[i]);
dates.push_back(string(buf)); //string(Dates[i]);
mxFree(buf);
}
}
@ -726,7 +726,7 @@ main(int nrhs, const char *prhs[])
mxArray *tmp = mxGetField(plan_struct, i, "exo");
if (tmp)
{
char name [100];
char name[100];
mxGetString(tmp, name, 100);
splan[i].var = name;
SymbolType variable_type = SymbolType::endogenous;
@ -744,7 +744,7 @@ main(int nrhs, const char *prhs[])
tmp = mxGetField(plan_struct, i, "var");
if (tmp)
{
char name [100];
char name[100];
mxGetString(tmp, name, 100);
splan[i].exo = name;
SymbolType variable_type;
@ -778,7 +778,7 @@ main(int nrhs, const char *prhs[])
mexPrintf(" plan fliping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it->var.c_str(), it->var_num, it->exo.c_str(), it->exo_num);
else
mexPrintf(" plan shocks on var=%s for the following periods and with the following values:\n", it->var.c_str());
for (vector<pair<int, double> >::iterator it1 = it->per_value.begin(); it1 != it->per_value.end(); it1++)
for (vector<pair<int, double>>::iterator it1 = it->per_value.begin(); it1 != it->per_value.end(); it1++)
{
mexPrintf(" %3d %10.5f\n", it1->first, it1->second);
}
@ -804,7 +804,7 @@ main(int nrhs, const char *prhs[])
mxArray *tmp = mxGetField(pfplan_struct, i, "var");
if (tmp)
{
char name [100];
char name[100];
mxGetString(tmp, name, 100);
spfplan[i].var = name;
SymbolType variable_type = SymbolType::endogenous;
@ -822,7 +822,7 @@ main(int nrhs, const char *prhs[])
tmp = mxGetField(pfplan_struct, i, "exo");
if (tmp)
{
char name [100];
char name[100];
mxGetString(tmp, name, 100);
spfplan[i].exo = name;
SymbolType variable_type;
@ -856,7 +856,7 @@ main(int nrhs, const char *prhs[])
mexPrintf(" plan flipping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it->var.c_str(), it->var_num, it->exo.c_str(), it->exo_num);
else
mexPrintf(" plan shocks on var=%s (%d) for the following periods and with the following values:\n", it->var.c_str(), it->var_num);
for (vector<pair<int, double> >::iterator it1 = it->per_value.begin(); it1 != it->per_value.end(); it1++)
for (vector<pair<int, double>>::iterator it1 = it->per_value.begin(); it1 != it->per_value.end(); it1++)
{
mexPrintf(" %3d %10.5f\n", it1->first, it1->second);
}

View File

@ -347,7 +347,7 @@ read_struct(FILE *fid)
fscanf(fid, "%d", &size_2);
vector<string> fieldnames;
vector<mxArray *> v_Array;
vector<vector<mxArray * > > vv_Array;
vector<vector<mxArray * >> vv_Array;
for (unsigned int j = 0; j < size_1 * size_2; j++)
{
for (unsigned int i = 0; i < nfields; i++)

View File

@ -73,7 +73,7 @@ public:
double *data;
mxArray_type type;
vector<string> field_name;
vector<vector<mxArray_tag *> > field_array;
vector<vector<mxArray_tag *>> field_array;
mxArray_tag();
};

View File

@ -29,7 +29,9 @@ class DynamicModelAC
protected:
int ntt; // Size of vector of temporary terms
public:
DynamicModelAC(int ntt_arg) : ntt{ntt_arg} {};
DynamicModelAC(int ntt_arg) : ntt{ntt_arg}
{
};
virtual ~DynamicModelAC() = default;
virtual void eval(const Vector &y, const Vector &x, const Vector &params, const Vector &ySteady,
Vector &residual, std::vector<TwoDMatrix> &md) = 0;

View File

@ -35,7 +35,7 @@
#include "dynamic_abstract_class.hh"
using dynamic_tt_fct = void (*)(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, double *T);
using dynamic_deriv_fct = void (*) (const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, const double *T, double *deriv);
using dynamic_deriv_fct = void (*)(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, const double *T, double *deriv);
/**
* creates pointer to Dynamic function inside <model>_dynamic.dll

View File

@ -236,4 +236,3 @@ DynareStateNameList::DynareStateNameList(const KordpDynare &dynare, const Dynare
for (int i = 0; i < dynare.nexog(); i++)
names.emplace_back(denl.getName(i));
}

View File

@ -312,4 +312,3 @@ extern "C" {
plhs[0] = mxCreateDoubleScalar(0);
} // end of mexFunction()
} // end of extern C

View File

@ -70,7 +70,7 @@ main(int argc, char *argv[])
};
npar = 2; //(int)mxGetN(mxFldp);
TwoDMatrix *vCov = new TwoDMatrix(npar, npar, (d2Dparams));
double dYSparams [16] = { // 27 mxGetData(mxFldp);
double dYSparams[16] = { // 27 mxGetData(mxFldp);
// 1.0110, 2.2582, 5.8012, 0.5808,
1.0110, 2.2582, 0.4477, 1.0000,
4.5959, 1.0212, 5.8012, 0.8494,
@ -117,7 +117,7 @@ main(int argc, char *argv[])
for (int v = 0; v < nEndo; v++)
(*var_order_vp)[v] = var_order[v];
const double ll_incidence [] //[3][18]
const double ll_incidence[] //[3][18]
= {
1, 5, 21,
2, 6, 22,

View File

@ -31,7 +31,7 @@
#include <omp.h>
#define FIRST_ORDER_LOOP 1// Comment out this line to use mkl-blas instead of loops when computing ghx*yhat and ghu*epsilon
#define FIRST_ORDER_LOOP 1 // Comment out this line to use mkl-blas instead of loops when computing ghx*yhat and ghu*epsilon
std::tuple<std::vector<int>, std::vector<int>, std::vector<int>>
set_vector_of_indices(int n, int r)
@ -231,10 +231,10 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexErrMsgTxt("Too many output arguments.");
// Get dimensions.
size_t n = mxGetM(prhs[0]);// Number of states.
size_t s = mxGetN(prhs[0]);// Number of particles.
size_t q = mxGetM(prhs[1]);// Number of innovations.
size_t m = mxGetM(prhs[2]);// Number of elements in the union of states and observed variables.
size_t n = mxGetM(prhs[0]); // Number of states.
size_t s = mxGetN(prhs[0]); // Number of particles.
size_t q = mxGetM(prhs[1]); // Number of innovations.
size_t m = mxGetM(prhs[2]); // Number of elements in the union of states and observed variables.
//mexPrintf("\n s (the number of column of yhat) is equal to %d.", s);
//mexPrintf("\n The number of column of epsilon is %d.", mxGetN(prhs[1]));
// Check the dimensions.

View File

@ -37,13 +37,13 @@
struct ParticleWorker : public sthread::detach_thread
{
const int npred_both, exo_nbr;
const std::pair<size_t,size_t> particle_range;
const std::pair<size_t, size_t> particle_range;
const ConstGeneralMatrix &yhat, &epsilon;
const Vector &ys_reordered;
const UnfoldDecisionRule &dr;
GeneralMatrix &ynext;
ParticleWorker(int npred_both_arg, int exo_nbr_arg, std::pair<size_t,size_t> particle_range_arg,
ParticleWorker(int npred_both_arg, int exo_nbr_arg, std::pair<size_t, size_t> particle_range_arg,
const ConstGeneralMatrix &yhat_arg, const ConstGeneralMatrix &epsilon_arg,
const Vector &ys_reordered_arg, const UnfoldDecisionRule &dr_arg,
GeneralMatrix &ynext_arg)
@ -52,7 +52,8 @@ struct ParticleWorker : public sthread::detach_thread
ynext{ynext_arg}
{
}
void operator()(std::mutex &mut) override
void
operator()(std::mutex &mut) override
{
Vector dyu(npred_both+exo_nbr);
Vector dy(dyu, 0, npred_both);

View File

@ -48,16 +48,16 @@ mexFunction(int nlhs, mxArray *plhs[],
/*
* Allocate memory
*/
maxnargs = static_cast<int> (mxGetN(prhs[0])/2+1);
argument = static_cast<char *> (mxCalloc(mxGetN(prhs[0])+1, sizeof(char)));
args = static_cast<char **> (mxCalloc(maxnargs, sizeof(char *)));
maxnargs = static_cast<int>(mxGetN(prhs[0])/2+1);
argument = static_cast<char *>(mxCalloc(mxGetN(prhs[0])+1, sizeof(char)));
args = static_cast<char **>(mxCalloc(maxnargs, sizeof(char *)));
if (argument == NULL || args == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("Error in MS-SBVAR MEX file: could not allocate memory. (1)");
/*
* Create argument string from prhs and parse to create args / nargs
*/
if (!(args[nargs] = static_cast<char *> (mxCalloc(strlen(mainarg)+1, sizeof(char)))))
if (!(args[nargs] = static_cast<char *>(mxCalloc(strlen(mainarg)+1, sizeof(char)))))
DYN_MEX_FUNC_ERR_MSG_TXT("Error in MS-SBVAR MEX file: could not allocate memory. (2)");
strncpy(args[nargs++], mainarg, strlen(mainarg));
@ -68,7 +68,7 @@ mexFunction(int nlhs, mxArray *plhs[],
beginarg = &argument[0];
while ((n = strcspn(beginarg, " ")))
{
if (!(args[nargs] = static_cast<char *> (mxCalloc(n+1, sizeof(char)))))
if (!(args[nargs] = static_cast<char *>(mxCalloc(n+1, sizeof(char)))))
DYN_MEX_FUNC_ERR_MSG_TXT("Error in MS-SBVAR MEX file: could not allocate memory. (3)");
strncpy(args[nargs++], beginarg, n);

View File

@ -19,12 +19,12 @@
#if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
#include <dynmex.h>
# include <dynmex.h>
#ifdef __cplusplus
# ifdef __cplusplus
extern "C"
{
#endif
# endif
int constant_seed;
@ -34,7 +34,7 @@ extern "C"
throw "Error in MS-SBVAR MEX file.\n";
}
#ifdef __cplusplus
# ifdef __cplusplus
}
#endif
# endif
#endif

View File

@ -39,7 +39,9 @@ public:
// Used to store error messages (as exceptions cannot cross the OpenMP boundary)
static std::string error_msg;
DynamicModelCaller(bool linear_arg, bool compute_jacobian_arg) : linear{linear_arg}, compute_jacobian{compute_jacobian_arg} {};
DynamicModelCaller(bool linear_arg, bool compute_jacobian_arg) : linear{linear_arg}, compute_jacobian{compute_jacobian_arg}
{
};
virtual ~DynamicModelCaller() = default;
virtual double &y(size_t i) const = 0;
virtual double jacobian(size_t i) const = 0;
@ -55,7 +57,7 @@ private:
static void *dynamic_mex;
#endif
using dynamic_tt_fct = void (*)(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, double *T);
using dynamic_deriv_fct = void (*) (const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, const double *T, double *deriv);
using dynamic_deriv_fct = void (*)(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, const double *T, double *deriv);
static dynamic_tt_fct residual_tt_fct, g1_tt_fct;
static dynamic_deriv_fct residual_fct, g1_fct;
size_t nb_row_x;
@ -65,8 +67,16 @@ private:
public:
DynamicModelDllCaller(size_t ntt, mwIndex nx, mwIndex ny, size_t ndynvars, const double *x_arg, size_t nb_row_x_arg, const double *params_arg, const double *steady_state_arg, bool linear_arg, bool compute_jacobian_arg);
virtual ~DynamicModelDllCaller() = default;
double &y(size_t i) const override { return y_p[i]; };
double jacobian(size_t i) const override { return jacobian_p[i]; };
double &
y(size_t i) const override
{
return y_p[i];
};
double
jacobian(size_t i) const override
{
return jacobian_p[i];
};
void eval(int it, double *resid) override;
static void load_dll(const std::string &basename);
static void unload_dll();
@ -85,13 +95,23 @@ private:
public:
DynamicModelMatlabCaller(std::string basename_arg, size_t ntt, size_t ndynvars, const mxArray *x_mx_arg, const mxArray *params_mx_arg, const mxArray *steady_state_mx_arg, bool linear_arg, bool compute_jacobian_arg);
~DynamicModelMatlabCaller() override;
double &y(size_t i) const override { return mxGetPr(y_mx)[i]; };
double jacobian(size_t i) const override { return jacobian_mx ? mxGetPr(jacobian_mx)[i] : std::numeric_limits<double>::quiet_NaN(); };
double &
y(size_t i) const override
{
return mxGetPr(y_mx)[i];
};
double
jacobian(size_t i) const override
{
return jacobian_mx ? mxGetPr(jacobian_mx)[i] : std::numeric_limits<double>::quiet_NaN();
};
void eval(int it, double *resid) override;
class Exception {
class Exception
{
public:
const std::string msg;
Exception(std::string msg_arg) : msg{std::move(msg_arg)} {};
Exception(std::string msg_arg) : msg{std::move(msg_arg)}
{
};
};
};

View File

@ -148,15 +148,15 @@ usphere(int d, int n, T *U)
{
icdfm(n*d, U);
#pragma omp parallel for
for (int j = 0; j < n; j++)// sequence index.
for (int j = 0; j < n; j++) // sequence index.
{
int k = j*d;
double norm = 0.0;
for (int i = 0; i < d; i++)// dimension index.
for (int i = 0; i < d; i++) // dimension index.
norm = norm + U[k+i]*U[k+i];
norm = sqrt(norm);
for (int i = 0; i < d; i++)// dimension index.
for (int i = 0; i < d; i++) // dimension index.
U[k+i] = U[k+i]/norm;
}
}
@ -167,15 +167,15 @@ usphereRadius(int d, int n, double radius, T *U)
{
icdfm(n*d, U);
#pragma omp parallel for
for (int j = 0; j < n; j++)// sequence index.
for (int j = 0; j < n; j++) // sequence index.
{
int k = j*d;
double norm = 0.0;
for (int i = 0; i < d; i++)// dimension index.
for (int i = 0; i < d; i++) // dimension index.
norm = norm + U[k+i]*U[k+i];
norm = sqrt(norm);
for (int i = 0; i < d; i++)// dimension index.
for (int i = 0; i < d; i++) // dimension index.
U[k+i] = radius*U[k+i]/norm;
}
}