preprocessor: print JSON deriv detail by default; use option to print less-detailed versions of dynamic/static models
parent
c59b6ab035
commit
955fb4f003
141
DynamicModel.cc
141
DynamicModel.cc
|
@ -5658,13 +5658,17 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
|
|||
expr_t d1 = it->second;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\""
|
||||
<< ", \"shift\": " << getLagByDerivID(var);
|
||||
jacobian_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
jacobian_output << "{\"row\": " << eq + 1;
|
||||
jacobian_output << ", \"col\": " << col + 1
|
||||
<< ", \"val\": \"";
|
||||
|
||||
jacobian_output << ", \"col\": " << col + 1;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\""
|
||||
<< ", \"shift\": " << getLagByDerivID(var);
|
||||
|
||||
jacobian_output << ", \"val\": \"";
|
||||
d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms);
|
||||
jacobian_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -5695,19 +5699,22 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
|
|||
int col_nb_sym = id2 * dynJacobianColsNbr + id1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"shift1\": " << getLagByDerivID(var1)
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"shift2\": " << getLagByDerivID(var2);
|
||||
hessian_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
hessian_output << "{\"row\": " << eq + 1;
|
||||
|
||||
hessian_output << ", \"col\": [" << col_nb + 1;
|
||||
if (id1 != id2)
|
||||
hessian_output << ", " << col_nb_sym + 1;
|
||||
hessian_output << "]"
|
||||
<< ", \"val\": \"";
|
||||
hessian_output << "]";
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"shift1\": " << getLagByDerivID(var1)
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"shift2\": " << getLagByDerivID(var2);
|
||||
|
||||
hessian_output << ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms);
|
||||
hessian_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -5735,13 +5742,7 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
|
|||
expr_t d3 = it->second;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivatives_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"shift1\": " << getLagByDerivID(var1)
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"shift2\": " << getLagByDerivID(var2)
|
||||
<< ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\""
|
||||
<< ", \"shift3\": " << getLagByDerivID(var3);
|
||||
third_derivatives_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
third_derivatives_output << "{\"row\": " << eq + 1;
|
||||
|
||||
|
@ -5763,17 +5764,26 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c
|
|||
third_derivatives_output << ", ";
|
||||
third_derivatives_output << *it2 + 1;
|
||||
}
|
||||
third_derivatives_output << "]"
|
||||
<< ", \"val\": \"";
|
||||
third_derivatives_output << "]";
|
||||
|
||||
if (writeDetails)
|
||||
third_derivatives_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"shift1\": " << getLagByDerivID(var1)
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"shift2\": " << getLagByDerivID(var2)
|
||||
<< ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\""
|
||||
<< ", \"shift3\": " << getLagByDerivID(var3);
|
||||
|
||||
third_derivatives_output << ", \"val\": \"";
|
||||
d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms);
|
||||
third_derivatives_output << "\"}" << endl;
|
||||
}
|
||||
third_derivatives_output << "]}";
|
||||
|
||||
if (writeDetails)
|
||||
output << "\"dynamic_model_derivative_details\": {";
|
||||
output << "\"dynamic_model\": {";
|
||||
else
|
||||
output << "\"dynamic_model_derivatives\": {";
|
||||
output << "\"dynamic_model_simple\": {";
|
||||
output << model_local_vars_output.str()
|
||||
<< ", " << model_output.str()
|
||||
<< ", " << jacobian_output.str()
|
||||
|
@ -5823,12 +5833,16 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
jacobian_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
jacobian_output << "{\"row\": " << eq + 1;
|
||||
jacobian_output << ", \"param_col\": " << param_col + 1
|
||||
<< ", \"val\": \"";
|
||||
|
||||
jacobian_output << ", \"param_col\": " << param_col + 1;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
|
||||
jacobian_output << ", \"val\": \"";
|
||||
d1->writeJsonOutput(jacobian_output, params_derivs_temporary_terms, tef_terms);
|
||||
jacobian_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -5853,15 +5867,19 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\""
|
||||
<< ", \"lag\": " << getLagByDerivID(var)
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
hessian_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
hessian_output << "{\"row\": " << eq + 1;
|
||||
|
||||
hessian_output << ", \"var_col\": " << var_col + 1
|
||||
<< ", \"param_col\": " << param_col + 1
|
||||
<< ", \"val\": \"";
|
||||
<< ", \"param_col\": " << param_col + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\""
|
||||
<< ", \"lag\": " << getLagByDerivID(var)
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
|
||||
hessian_output << ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian_output, params_derivs_temporary_terms, tef_terms);
|
||||
hessian_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -5887,14 +5905,17 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian1_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
hessian1_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
hessian1_output << "{\"row\": " << eq + 1;
|
||||
hessian1_output << ", \"param1_col\": " << param1_col + 1
|
||||
<< ", \"param2_col\": " << param2_col + 1
|
||||
<< ", \"val\": \"";
|
||||
<< ", \"param2_col\": " << param2_col + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian1_output << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
|
||||
hessian1_output << ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian1_output, params_derivs_temporary_terms, tef_terms);
|
||||
hessian1_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -5922,17 +5943,21 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(var) << "\""
|
||||
third_derivs_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
third_derivs_output << "{\"row\": " << eq + 1;
|
||||
|
||||
third_derivs_output << ", \"var_col\": " << var_col + 1
|
||||
<< ", \"param1_col\": " << param1_col + 1
|
||||
<< ", \"param2_col\": " << param2_col + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs_output << ", \"var\": \"" << symbol_table.getName(var) << "\""
|
||||
<< ", \"lag\": " << getLagByDerivID(var)
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
else
|
||||
third_derivs_output << "{\"row\": " << eq + 1;
|
||||
third_derivs_output << ", \"var_col\": " << var_col + 1
|
||||
<< ", \"param1_col\": " << param1_col + 1
|
||||
<< ", \"param2_col\": " << param2_col + 1
|
||||
<< ", \"val\": \"";
|
||||
|
||||
third_derivs_output << ", \"val\": \"";
|
||||
d2->writeJsonOutput(third_derivs_output, params_derivs_temporary_terms, tef_terms);
|
||||
third_derivs_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -5961,27 +5986,31 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs1_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
third_derivs1_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
third_derivs1_output << "{\"row\": " << eq + 1;
|
||||
|
||||
third_derivs1_output << ", \"var1_col\": " << var1_col + 1
|
||||
<< ", \"var2_col\": " << var2_col + 1
|
||||
<< ", \"param_col\": " << param_col + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs1_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"lag1\": " << getLagByDerivID(var1)
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"lag2\": " << getLagByDerivID(var2)
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
else
|
||||
third_derivs1_output << "{\"row\": " << eq + 1;
|
||||
third_derivs1_output << ", \"var1_col\": " << var1_col + 1
|
||||
<< ", \"var2_col\": " << var2_col + 1
|
||||
<< ", \"param_col\": " << param_col + 1
|
||||
<< ", \"val\": \"";
|
||||
|
||||
third_derivs1_output << ", \"val\": \"";
|
||||
d2->writeJsonOutput(third_derivs1_output, params_derivs_temporary_terms, tef_terms);
|
||||
third_derivs1_output << "\"}" << endl;
|
||||
}
|
||||
third_derivs1_output << "]}" << endl;
|
||||
|
||||
if (writeDetails)
|
||||
output << "\"dynamic_model_params_derivative_details\": {";
|
||||
output << "\"dynamic_model_params_derivative\": {";
|
||||
else
|
||||
output << "\"dynamic_model_params_derivatives\": {";
|
||||
output << "\"dynamic_model_params_derivatives_simple\": {";
|
||||
output << model_local_vars_output.str()
|
||||
<< ", " << model_output.str()
|
||||
<< ", " << jacobian_output.str()
|
||||
|
|
|
@ -45,7 +45,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool
|
|||
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
|
||||
, bool cygwin, bool msvc, bool mingw
|
||||
#endif
|
||||
, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail
|
||||
, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple
|
||||
);
|
||||
|
||||
void main1(char *modfile, string &basename, bool debug, bool save_macro, string &save_macro_file,
|
||||
|
@ -62,7 +62,7 @@ usage()
|
|||
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
|
||||
<< " [cygwin] [msvc] [mingw]"
|
||||
#endif
|
||||
<< "[json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonprintderivdetail]"
|
||||
<< "[json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple]"
|
||||
<< endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ main(int argc, char **argv)
|
|||
JsonOutputPointType json = nojson;
|
||||
JsonFileOutputType json_output_mode = file;
|
||||
bool onlyjson = false;
|
||||
bool jsonprintderivdetail = false;
|
||||
bool jsonderivsimple = false;
|
||||
LanguageOutputType language = matlab;
|
||||
|
||||
// Parse options
|
||||
|
@ -301,8 +301,8 @@ main(int argc, char **argv)
|
|||
json_output_mode = standardout;
|
||||
else if (!strcmp(argv[arg], "onlyjson"))
|
||||
onlyjson = true;
|
||||
else if (!strcmp(argv[arg], "jsonprintderivdetail"))
|
||||
jsonprintderivdetail = true;
|
||||
else if (!strcmp(argv[arg], "jsonderivsimple"))
|
||||
jsonderivsimple = true;
|
||||
else if (strlen(argv[arg]) >= 4 && !strncmp(argv[arg], "json", 4))
|
||||
{
|
||||
if (strlen(argv[arg]) <= 5 || argv[arg][4] != '=')
|
||||
|
@ -370,7 +370,7 @@ main(int argc, char **argv)
|
|||
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
|
||||
, cygwin, msvc, mingw
|
||||
#endif
|
||||
, json, json_output_mode, onlyjson, jsonprintderivdetail
|
||||
, json, json_output_mode, onlyjson, jsonderivsimple
|
||||
);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -34,7 +34,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear
|
|||
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
|
||||
, bool cygwin, bool msvc, bool mingw
|
||||
#endif
|
||||
, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail
|
||||
, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple
|
||||
)
|
||||
{
|
||||
ParsingDriver p(warnings, nostrict);
|
||||
|
@ -60,7 +60,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear
|
|||
// Do computations
|
||||
mod_file->computingPass(no_tmp_terms, output_mode, params_derivs_order);
|
||||
if (json == computingpass)
|
||||
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, jsonprintderivdetail);
|
||||
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, jsonderivsimple);
|
||||
|
||||
// Write outputs
|
||||
if (output_mode != none)
|
||||
|
|
82
ModFile.cc
82
ModFile.cc
|
@ -1262,7 +1262,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
|
|||
}
|
||||
|
||||
void
|
||||
ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail)
|
||||
ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple)
|
||||
{
|
||||
if (json == nojson)
|
||||
return;
|
||||
|
@ -1276,7 +1276,7 @@ ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonF
|
|||
symbol_table.unfreeze();
|
||||
|
||||
if (json == computingpass)
|
||||
writeJsonComputingPassOutput(basename, json_output_mode, jsonprintderivdetail);
|
||||
writeJsonComputingPassOutput(basename, json_output_mode, jsonderivsimple);
|
||||
|
||||
switch (json)
|
||||
{
|
||||
|
@ -1396,16 +1396,16 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
|
|||
}
|
||||
|
||||
void
|
||||
ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonprintderivdetail) const
|
||||
ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const
|
||||
{
|
||||
ostringstream static_output, static_detail_output;
|
||||
ostringstream static_output, static_simple_output;
|
||||
static_output << "{";
|
||||
static_model.writeJsonComputingPassOutput(static_output, false);
|
||||
static_model.writeJsonComputingPassOutput(static_output, true);
|
||||
static_output << "}" << endl;
|
||||
|
||||
ostringstream dynamic_output, dynamic_detail_output;
|
||||
ostringstream dynamic_output, dynamic_simple_output;
|
||||
dynamic_output << "{";
|
||||
dynamic_model.writeJsonComputingPassOutput(dynamic_output, false);
|
||||
dynamic_model.writeJsonComputingPassOutput(dynamic_output, true);
|
||||
dynamic_output << "}" << endl;
|
||||
|
||||
ostringstream original_model_output;
|
||||
|
@ -1413,42 +1413,42 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType
|
|||
original_model.writeJsonOriginalModelOutput(original_model_output);
|
||||
original_model_output << "}" << endl;
|
||||
|
||||
ostringstream tmp_out, static_paramsd_output, static_paramsd_detail_output;
|
||||
ostringstream tmp_out, static_paramsd_output, static_paramsd_simple_output;
|
||||
tmp_out << "";
|
||||
static_paramsd_output << "";
|
||||
static_paramsd_detail_output << "";
|
||||
static_model.writeJsonParamsDerivativesFile(tmp_out, false);
|
||||
static_paramsd_simple_output << "";
|
||||
static_model.writeJsonParamsDerivativesFile(tmp_out, true);
|
||||
if (!tmp_out.str().empty())
|
||||
static_paramsd_output << "{" << tmp_out.str() << "}" << endl;
|
||||
|
||||
ostringstream tmp1_out, dynamic_paramsd_output, dynamic_paramsd_detail_output;
|
||||
ostringstream tmp1_out, dynamic_paramsd_output, dynamic_paramsd_simple_output;
|
||||
tmp1_out << "";
|
||||
dynamic_paramsd_output << "";
|
||||
dynamic_paramsd_detail_output << "";
|
||||
dynamic_model.writeJsonParamsDerivativesFile(tmp1_out, false);
|
||||
dynamic_paramsd_simple_output << "";
|
||||
dynamic_model.writeJsonParamsDerivativesFile(tmp1_out, true);
|
||||
if (!tmp1_out.str().empty())
|
||||
dynamic_paramsd_output << "{" << tmp1_out.str() << "}" << endl;
|
||||
|
||||
if (jsonprintderivdetail)
|
||||
if (jsonderivsimple)
|
||||
{
|
||||
static_detail_output << "{";
|
||||
static_model.writeJsonComputingPassOutput(static_detail_output, true);
|
||||
static_detail_output << "}";
|
||||
static_simple_output << "{";
|
||||
static_model.writeJsonComputingPassOutput(static_simple_output, false);
|
||||
static_simple_output << "}";
|
||||
|
||||
dynamic_detail_output << "{";
|
||||
dynamic_model.writeJsonComputingPassOutput(dynamic_detail_output, true);
|
||||
dynamic_detail_output << "}";
|
||||
dynamic_simple_output << "{";
|
||||
dynamic_model.writeJsonComputingPassOutput(dynamic_simple_output, false);
|
||||
dynamic_simple_output << "}";
|
||||
|
||||
ostringstream tmpd_out, tmpd1_out;
|
||||
tmpd_out << "";
|
||||
tmpd1_out << "";
|
||||
static_model.writeJsonParamsDerivativesFile(tmpd_out, true);
|
||||
if (!tmpd_out.str().empty())
|
||||
static_paramsd_detail_output << "{" << tmpd_out.str() << "}" << endl;
|
||||
static_paramsd_simple_output << "{" << tmpd_out.str() << "}" << endl;
|
||||
|
||||
dynamic_model.writeJsonParamsDerivativesFile(tmpd1_out, true);
|
||||
if (!tmpd1_out.str().empty())
|
||||
dynamic_paramsd_detail_output << "{" << tmpd1_out.str() << "}" << endl;
|
||||
dynamic_paramsd_simple_output << "{" << tmpd1_out.str() << "}" << endl;
|
||||
}
|
||||
|
||||
if (json_output_mode == standardout)
|
||||
|
@ -1463,16 +1463,16 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType
|
|||
if (!dynamic_paramsd_output.str().empty())
|
||||
cout << dynamic_paramsd_output.str() << endl;
|
||||
|
||||
if (jsonprintderivdetail)
|
||||
if (jsonderivsimple)
|
||||
{
|
||||
cout << static_detail_output.str() << endl
|
||||
<< dynamic_detail_output.str() << endl;
|
||||
cout << static_simple_output.str() << endl
|
||||
<< dynamic_simple_output.str() << endl;
|
||||
|
||||
if (!static_paramsd_detail_output.str().empty())
|
||||
cout << static_paramsd_detail_output.str() << endl;
|
||||
if (!static_paramsd_simple_output.str().empty())
|
||||
cout << static_paramsd_simple_output.str() << endl;
|
||||
|
||||
if (!dynamic_paramsd_detail_output.str().empty())
|
||||
cout << dynamic_paramsd_detail_output.str() << endl;
|
||||
if (!dynamic_paramsd_simple_output.str().empty())
|
||||
cout << dynamic_paramsd_simple_output.str() << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1492,32 +1492,32 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType
|
|||
writeJsonFileHelper(fname_static, static_output);
|
||||
writeJsonFileHelper(fname_dynamic, dynamic_output);
|
||||
|
||||
if (jsonprintderivdetail)
|
||||
if (jsonderivsimple)
|
||||
{
|
||||
string fname_static_details, fname_dynamic_details;
|
||||
fname_static_details = basename + "_static_details.json";
|
||||
fname_dynamic_details = basename + "_dynamic_details.json";
|
||||
string fname_static_simple, fname_dynamic_simple;
|
||||
fname_static_simple = basename + "_static_simple.json";
|
||||
fname_dynamic_simple = basename + "_dynamic_simple.json";
|
||||
|
||||
writeJsonFileHelper(fname_static_details, static_detail_output);
|
||||
writeJsonFileHelper(fname_dynamic_details, dynamic_detail_output);
|
||||
writeJsonFileHelper(fname_static_simple, static_simple_output);
|
||||
writeJsonFileHelper(fname_dynamic_simple, dynamic_simple_output);
|
||||
}
|
||||
|
||||
if (!static_paramsd_output.str().empty())
|
||||
{
|
||||
string fname_static_params, fname_static_params_details;
|
||||
string fname_static_params, fname_static_params_simple;
|
||||
fname_static_params = basename + "_static_params_derivs.json";
|
||||
fname_static_params_details = basename + "_static_params_derivs_details.json";
|
||||
fname_static_params_simple = basename + "_static_params_derivs_simple.json";
|
||||
writeJsonFileHelper(fname_static_params, static_paramsd_output);
|
||||
writeJsonFileHelper(fname_static_params_details, static_paramsd_detail_output);
|
||||
writeJsonFileHelper(fname_static_params_simple, static_paramsd_simple_output);
|
||||
}
|
||||
|
||||
if (!dynamic_paramsd_output.str().empty())
|
||||
{
|
||||
string fname_dynamic_params, fname_dynamic_params_details;
|
||||
string fname_dynamic_params, fname_dynamic_params_simple;
|
||||
fname_dynamic_params = basename + "_params_derivs.json";
|
||||
fname_dynamic_params_details = basename + "_params_derivs_details.json";
|
||||
fname_dynamic_params_simple = basename + "_params_derivs_simple.json";
|
||||
writeJsonFileHelper(fname_dynamic_params, dynamic_paramsd_output);
|
||||
writeJsonFileHelper(fname_dynamic_params_details, dynamic_paramsd_detail_output);
|
||||
writeJsonFileHelper(fname_dynamic_params_simple, dynamic_paramsd_simple_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ private:
|
|||
WarningConsolidation &warnings;
|
||||
//! Functions used in writing of JSON outut. See writeJsonOutput
|
||||
void writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType json_output_mode, bool transformpass, bool computingpass) const;
|
||||
void writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonprintderivdetail) const;
|
||||
void writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const;
|
||||
void writeJsonFileHelper(string &fname, ostringstream &output) const;
|
||||
public:
|
||||
//! Add a statement
|
||||
|
@ -174,7 +174,7 @@ public:
|
|||
//! Initially created to enable Julia to work with .mod files
|
||||
//! Potentially outputs ModFile after the various parts of processing (parsing, checkPass, transformPass, computingPass)
|
||||
//! Allows user of other host language platforms (python, fortran, etc) to provide support for dynare .mod files
|
||||
void writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail = false);
|
||||
void writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple = false);
|
||||
};
|
||||
|
||||
#endif // ! MOD_FILE_HH
|
||||
|
|
110
StaticModel.cc
110
StaticModel.cc
|
@ -2467,12 +2467,16 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
|
|||
expr_t d1 = it->second;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(symb_id) << "\"";
|
||||
jacobian_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
jacobian_output << "{\"row\": " << eq + 1;
|
||||
jacobian_output << ", \"col\": " << col + 1
|
||||
<< ", \"val\": \"";
|
||||
|
||||
jacobian_output << ", \"col\": " << col + 1;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << ", \"var\": \"" << symbol_table.getName(symb_id) << "\"";
|
||||
|
||||
jacobian_output << ", \"val\": \"";
|
||||
d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms);
|
||||
jacobian_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -2506,13 +2510,16 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
|
|||
int col_sym = tsid2*symbol_table.endo_nbr()+tsid1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(symb_id1) << "\""
|
||||
<< ", \"var2\": \"" << symbol_table.getName(symb_id2) << "\"";
|
||||
hessian_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
hessian_output << "{\"row\": " << eq + 1;
|
||||
|
||||
hessian_output << ", \"col\": [" << col + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << ", \"var1\": \"" << symbol_table.getName(symb_id1) << "\""
|
||||
<< ", \"var2\": \"" << symbol_table.getName(symb_id2) << "\"";
|
||||
|
||||
if (symb_id1 != symb_id2)
|
||||
hessian_output << ", " << col_sym + 1;
|
||||
hessian_output << "]"
|
||||
|
@ -2544,10 +2551,7 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
|
|||
expr_t d3 = it->second;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivatives_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\"";
|
||||
third_derivatives_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
third_derivatives_output << "{\"row\": " << eq + 1;
|
||||
|
||||
|
@ -2569,17 +2573,23 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co
|
|||
third_derivatives_output << ", ";
|
||||
third_derivatives_output << *it2 + 1;
|
||||
}
|
||||
third_derivatives_output << "]"
|
||||
<< ", \"val\": \"";
|
||||
third_derivatives_output << "]";
|
||||
|
||||
if (writeDetails)
|
||||
third_derivatives_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\"";
|
||||
|
||||
third_derivatives_output << ", \"val\": \"";
|
||||
d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms);
|
||||
third_derivatives_output << "\"}" << endl;
|
||||
}
|
||||
third_derivatives_output << "]}";
|
||||
|
||||
if (writeDetails)
|
||||
output << "\"static_model_derivative_details\": {";
|
||||
output << "\"static_model\": {";
|
||||
else
|
||||
output << "\"static_model_derivatives\": {";
|
||||
output << "\"static_model_simple\": {";
|
||||
output << model_local_vars_output.str()
|
||||
<< ", " << model_output.str()
|
||||
<< ", " << jacobian_output.str()
|
||||
|
@ -2629,12 +2639,16 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
jacobian_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
jacobian_output << "{\"row\": " << eq + 1;
|
||||
jacobian_output << ", \"param_col\": " << param_col
|
||||
<< ", \"val\": \"";
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << ", \"param_col\": " << param_col;
|
||||
|
||||
jacobian_output << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
|
||||
jacobian_output << ", \"val\": \"";
|
||||
d1->writeJsonOutput(jacobian_output, params_derivs_temporary_terms, tef_terms);
|
||||
jacobian_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -2659,11 +2673,14 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\""
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
hessian_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
hessian_output << "{\"row\": " << eq + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\""
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
|
||||
hessian_output << ", \"var_col\": " << var_col
|
||||
<< ", \"param_col\": " << param_col
|
||||
<< ", \"val\": \"";
|
||||
|
@ -2692,14 +2709,18 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian1_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
hessian1_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
hessian1_output << "{\"row\": " << eq + 1;
|
||||
|
||||
hessian1_output << ", \"param1_col\": " << param1_col
|
||||
<< ", \"param2_col\": " << param2_col
|
||||
<< ", \"val\": \"";
|
||||
<< ", \"param2_col\": " << param2_col;
|
||||
|
||||
if (writeDetails)
|
||||
hessian1_output << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
|
||||
hessian1_output << ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian1_output, params_derivs_temporary_terms, tef_terms);
|
||||
hessian1_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -2727,16 +2748,19 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(var) << "\""
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
third_derivs_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
third_derivs_output << "{\"row\": " << eq + 1;
|
||||
third_derivs_output << ", \"var_col\": " << var_col
|
||||
<< ", \"param1_col\": " << param1_col
|
||||
<< ", \"param2_col\": " << param2_col
|
||||
<< ", \"val\": \"";
|
||||
<< ", \"param2_col\": " << param2_col;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs_output << ", \"var\": \"" << symbol_table.getName(var) << "\""
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
|
||||
third_derivs_output << ", \"val\": \"";
|
||||
d2->writeJsonOutput(third_derivs_output, params_derivs_temporary_terms, tef_terms);
|
||||
third_derivs_output << "\"}" << endl;
|
||||
}
|
||||
|
@ -2765,25 +2789,29 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails)
|
|||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs1_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
third_derivs1_output << "{\"eq\": " << eq + 1;
|
||||
else
|
||||
third_derivs1_output << "{\"row\": " << eq + 1;
|
||||
|
||||
third_derivs1_output << ", \"var1_col\": " << var1_col
|
||||
<< ", \"var2_col\": " << var2_col
|
||||
<< ", \"param_col\": " << param_col
|
||||
<< ", \"val\": \"";
|
||||
<< ", \"param_col\": " << param_col;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs1_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
|
||||
third_derivs1_output << ", \"val\": \"";
|
||||
d2->writeJsonOutput(third_derivs1_output, params_derivs_temporary_terms, tef_terms);
|
||||
third_derivs1_output << "\"}" << endl;
|
||||
}
|
||||
third_derivs1_output << "]}" << endl;
|
||||
|
||||
if (writeDetails)
|
||||
output << "\"static_model_params_derivative_details\": {";
|
||||
output << "\"static_model_params_derivative\": {";
|
||||
else
|
||||
output << "\"static_model_params_derivatives\": {";
|
||||
output << "\"static_model_params_derivatives_simple\": {";
|
||||
output << model_local_vars_output.str()
|
||||
<< ", " << model_output.str()
|
||||
<< ", " << jacobian_output.str()
|
||||
|
|
Loading…
Reference in New Issue