Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dynare
preprocessor
Commits
e19a1486
Commit
e19a1486
authored
Sep 05, 2018
by
Sébastien Villemot
Browse files
Convert ExprNodeOutputType into a class enum
Incidentally, replace the IS_* macros by inline functions.
parent
c6d4cb88
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
src/DynamicModel.cc
View file @
e19a1486
...
...
@@ -225,7 +225,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const
ExprNodeOutputType local_output_type;
Ufoss.str("");
local_output_type =
oM
atlabDynamicModelSparse;
local_output_type =
ExprNodeOutputType::m
atlabDynamicModelSparse;
if (global_temporary_terms)
local_temporary_terms = temporary_terms;
...
...
@@ -246,7 +246,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const
unsigned int block_mfs = getBlockMfs(block);
unsigned int block_recursive = block_size - block_mfs;
deriv_node_temp_terms_t tef_terms;
local_output_type =
oM
atlabDynamicModelSparse;
local_output_type =
ExprNodeOutputType::m
atlabDynamicModelSparse;
if (global_temporary_terms)
local_temporary_terms = temporary_terms;
...
...
@@ -415,7 +415,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const
{
output << " ";
// In the following, "Static" is used to avoid getting the "(it_)" subscripting
it->writeOutput(output,
oM
atlabStaticModelSparse, local_temporary_terms, {});
it->writeOutput(output,
ExprNodeOutputType::m
atlabStaticModelSparse, local_temporary_terms, {});
output << " = T_zeros;" << endl;
}
}
...
...
@@ -1803,7 +1803,7 @@ DynamicModel::writeSparseDynamicMFile(const string &basename) const
else
tmp_output << " ";
// In the following, "Static" is used to avoid getting the "(it_)" subscripting
temporary_term->writeOutput(tmp_output,
oM
atlabStaticModelSparse, temporary_terms, {});
temporary_term->writeOutput(tmp_output,
ExprNodeOutputType::m
atlabStaticModelSparse, temporary_terms, {});
}
if (tmp_output.str().length() > 0)
mDynamicModelFile << " global " << tmp_output.str() << ";\n";
...
...
@@ -1814,7 +1814,7 @@ DynamicModel::writeSparseDynamicMFile(const string &basename) const
{
tmp_output << " ";
// In the following, "Static" is used to avoid getting the "(it_)" subscripting
temporary_term->writeOutput(tmp_output,
oM
atlabStaticModelSparse, temporary_terms, {});
temporary_term->writeOutput(tmp_output,
ExprNodeOutputType::m
atlabStaticModelSparse, temporary_terms, {});
tmp_output << "=T_init;\n";
}
if (tmp_output.str().length() > 0)
...
...
@@ -2298,8 +2298,8 @@ DynamicModel::writeDynamicModel(const string &basename, ostream &DynamicOutput,
ostringstream third_derivatives_tt_output; // Used for storing third order derivatives temp terms
ostringstream third_derivatives_output; // Used for storing third order derivatives equations
ExprNodeOutputType output_type = (use_dll ?
o
CDynamicModel :
julia ?
oJuliaDynamicModel : oM
atlabDynamicModel);
ExprNodeOutputType output_type = (use_dll ?
ExprNodeOutputType::
CDynamicModel :
julia ?
ExprNodeOutputType::juliaDynamicModel : ExprNodeOutputType::m
atlabDynamicModel);
deriv_node_temp_terms_t tef_terms;
temporary_terms_t temp_term_union;
...
...
@@ -2366,7 +2366,7 @@ DynamicModel::writeDynamicModel(const string &basename, ostream &DynamicOutput,
int col_nb_sym = id2 * dynJacobianColsNbr + id1;
ostringstream for_sym;
if (output_type ==
oJ
uliaDynamicModel)
if (output_type ==
ExprNodeOutputType::j
uliaDynamicModel)
{
for_sym << "g2[" << eq + 1 << "," << col_nb + 1 << "]";
hessian_output << " @inbounds " << for_sym.str() << " = ";
...
...
@@ -2391,7 +2391,7 @@ DynamicModel::writeDynamicModel(const string &basename, ostream &DynamicOutput,
// Treating symetric elements
if (id1 != id2)
if (output_type ==
oJ
uliaDynamicModel)
if (output_type ==
ExprNodeOutputType::j
uliaDynamicModel)
hessian_output << " @inbounds g2[" << eq + 1 << "," << col_nb_sym + 1 << "] = "
<< for_sym.str() << endl;
else
...
...
@@ -2436,7 +2436,7 @@ DynamicModel::writeDynamicModel(const string &basename, ostream &DynamicOutput,
int ref_col = id1 * hessianColsNbr + id2 * dynJacobianColsNbr + id3;
ostringstream for_sym;
if (output_type ==
oJ
uliaDynamicModel)
if (output_type ==
ExprNodeOutputType::j
uliaDynamicModel)
{
for_sym << "g3[" << eq + 1 << "," << ref_col + 1 << "]";
third_derivatives_output << " @inbounds " << for_sym.str() << " = ";
...
...
@@ -2469,7 +2469,7 @@ DynamicModel::writeDynamicModel(const string &basename, ostream &DynamicOutput,
int k2 = 1; // Keeps the offset of the permutation relative to k
for (int col : cols)
if (col != ref_col)
if (output_type ==
oJ
uliaDynamicModel)
if (output_type ==
ExprNodeOutputType::j
uliaDynamicModel)
third_derivatives_output << " @inbounds g3[" << eq + 1 << "," << col + 1 << "] = "
<< for_sym.str() << endl;
else
...
...
@@ -2491,7 +2491,7 @@ DynamicModel::writeDynamicModel(const string &basename, ostream &DynamicOutput,
}
}
if (output_type ==
oM
atlabDynamicModel)
if (output_type ==
ExprNodeOutputType::m
atlabDynamicModel)
{
// Check that we don't have more than 32 nested parenthesis because Matlab does not suppor this. See Issue #1201
map<string, string> tmp_paren_vars;
...
...
@@ -2565,7 +2565,7 @@ DynamicModel::writeDynamicModel(const string &basename, ostream &DynamicOutput,
writeDynamicMatlabCompatLayer(basename);
}
else if (output_type ==
o
CDynamicModel)
else if (output_type ==
ExprNodeOutputType::
CDynamicModel)
{
DynamicOutput << "void Dynamic(double *y, double *x, int nb_row_x, double *params, double *steady_state, int it_, double *residual, double *g1, double *v2, double *v3)" << endl
<< "{" << endl
...
...
@@ -3428,7 +3428,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
// Write PacExpectationInfo
for (auto it : pac_expectation_info)
it->ExprNode::writeOutput(output,
oM
atlabDynamicModel);
it->ExprNode::writeOutput(output,
ExprNodeOutputType::m
atlabDynamicModel);
}
map<pair<int, pair<int, int >>, expr_t>
...
...
@@ -4652,7 +4652,7 @@ void
DynamicModel::writeSetAuxiliaryVariables(const string &basename, const bool julia) const
{
ostringstream output_func_body;
writeAuxVarRecursiveDefinitions(output_func_body,
oM
atlabDseries);
writeAuxVarRecursiveDefinitions(output_func_body,
ExprNodeOutputType::m
atlabDseries);
if (output_func_body.str().empty())
return;
...
...
@@ -5185,7 +5185,7 @@ DynamicModel::writeParamsDerivativesFile(const string &basename, bool julia) con
&& !hessian_params_derivatives.size())
return;
ExprNodeOutputType output_type = (julia ?
oJuliaDynamicModel : oM
atlabDynamicModel);
ExprNodeOutputType output_type = (julia ?
ExprNodeOutputType::juliaDynamicModel : ExprNodeOutputType::m
atlabDynamicModel);
ostringstream model_local_vars_output; // Used for storing model local vars
ostringstream model_output; // Used for storing model temp vars and equations
ostringstream jacobian_output; // Used for storing jacobian equations
...
...
@@ -5422,13 +5422,13 @@ DynamicModel::writeParamsDerivativesFile(const string &basename, bool julia) con
void
DynamicModel::writeLatexFile(const string &basename, const bool write_equation_tags) const
{
writeLatexModelFile(basename + "_dynamic",
oL
atexDynamicModel, write_equation_tags);
writeLatexModelFile(basename + "_dynamic",
ExprNodeOutputType::l
atexDynamicModel, write_equation_tags);
}
void
DynamicModel::writeLatexOriginalFile(const string &basename, const bool write_equation_tags) const
{
writeLatexModelFile(basename + "_original",
oL
atexDynamicModel, write_equation_tags);
writeLatexModelFile(basename + "_original",
ExprNodeOutputType::l
atexDynamicModel, write_equation_tags);
}
void
...
...
@@ -5908,7 +5908,7 @@ DynamicModel::isChecksumMatching(const string &basename) const
<< equation_tag.second.first
<< equation_tag.second.second;
ExprNodeOutputType buffer_type =
o
CDynamicModel;
ExprNodeOutputType buffer_type =
ExprNodeOutputType::
CDynamicModel;
for (int eq = 0; eq < (int) equations.size(); eq++)
{
...
...
src/ExprNode.cc
View file @
e19a1486
This diff is collapsed.
Click to expand it.
src/ExprNode.hh
View file @
e19a1486
...
...
@@ -67,65 +67,81 @@ using deriv_node_temp_terms_t = map<pair<int, vector<expr_t>>, int>;
using
diff_table_t
=
map
<
expr_t
,
map
<
int
,
expr_t
>>
;
//! Possible types of output when writing ExprNode(s)
enum
ExprNodeOutputType
enum
class
ExprNodeOutputType
{
oM
atlabStaticModel
,
//!< Matlab code, static model
oM
atlabDynamicModel
,
//!< Matlab code, dynamic model
oM
atlabStaticModelSparse
,
//!< Matlab code, static block decomposed model
oM
atlabDynamicModelSparse
,
//!< Matlab code, dynamic block decomposed model
o
CDynamicModel
,
//!< C code, dynamic model
o
CStaticModel
,
//!< C code, static model
oJ
uliaStaticModel
,
//!< Julia code, static model
oJ
uliaDynamicModel
,
//!< Julia code, dynamic model
oM
atlabOutsideModel
,
//!< Matlab code, outside model block (for example in initval)
oL
atexStaticModel
,
//!< LaTeX code, static model
oL
atexDynamicModel
,
//!< LaTeX code, dynamic model
oL
atexDynamicSteadyStateOperator
,
//!< LaTeX code, dynamic model, inside a steady state operator
oM
atlabDynamicSteadyStateOperator
,
//!< Matlab code, dynamic model, inside a steady state operator
oM
atlabDynamicSparseSteadyStateOperator
,
//!< Matlab code, dynamic block decomposed model, inside a steady state operator
o
CDynamicSteadyStateOperator
,
//!< C code, dynamic model, inside a steady state operator
oJ
uliaDynamicSteadyStateOperator
,
//!< Julia code, dynamic model, inside a steady state operator
oS
teadyStateFile
,
//!< Matlab code, in the generated steady state file
oJ
uliaSteadyStateFile
,
//!< Julia code, in the generated steady state file
oM
atlabDseries
,
//!< Matlab code for dseries
oE
pilogueFile
//!< Matlab code, in the generated epilogue file
m
atlabStaticModel
,
//!< Matlab code, static model
m
atlabDynamicModel
,
//!< Matlab code, dynamic model
m
atlabStaticModelSparse
,
//!< Matlab code, static block decomposed model
m
atlabDynamicModelSparse
,
//!< Matlab code, dynamic block decomposed model
CDynamicModel
,
//!< C code, dynamic model
CStaticModel
,
//!< C code, static model
j
uliaStaticModel
,
//!< Julia code, static model
j
uliaDynamicModel
,
//!< Julia code, dynamic model
m
atlabOutsideModel
,
//!< Matlab code, outside model block (for example in initval)
l
atexStaticModel
,
//!< LaTeX code, static model
l
atexDynamicModel
,
//!< LaTeX code, dynamic model
l
atexDynamicSteadyStateOperator
,
//!< LaTeX code, dynamic model, inside a steady state operator
m
atlabDynamicSteadyStateOperator
,
//!< Matlab code, dynamic model, inside a steady state operator
m
atlabDynamicSparseSteadyStateOperator
,
//!< Matlab code, dynamic block decomposed model, inside a steady state operator
CDynamicSteadyStateOperator
,
//!< C code, dynamic model, inside a steady state operator
j
uliaDynamicSteadyStateOperator
,
//!< Julia code, dynamic model, inside a steady state operator
s
teadyStateFile
,
//!< Matlab code, in the generated steady state file
j
uliaSteadyStateFile
,
//!< Julia code, in the generated steady state file
m
atlabDseries
,
//!< Matlab code for dseries
e
pilogueFile
//!< Matlab code, in the generated epilogue file
};
#define IS_MATLAB(output_type) ((output_type) == oMatlabStaticModel \
|| (output_type) == oMatlabDynamicModel \
|| (output_type) == oMatlabOutsideModel \
|| (output_type) == oMatlabStaticModelSparse \
|| (output_type) == oMatlabDynamicModelSparse \
|| (output_type) == oMatlabDynamicSteadyStateOperator \
|| (output_type) == oMatlabDynamicSparseSteadyStateOperator \
|| (output_type) == oSteadyStateFile \
|| (output_type) == oMatlabDseries \
|| (output_type) == oEpilogueFile)
#define IS_JULIA(output_type) ((output_type) == oJuliaStaticModel \
|| (output_type) == oJuliaDynamicModel \
|| (output_type) == oJuliaDynamicSteadyStateOperator \
|| (output_type) == oJuliaSteadyStateFile)
#define IS_C(output_type) ((output_type) == oCDynamicModel \
|| (output_type) == oCStaticModel \
|| (output_type) == oCDynamicSteadyStateOperator)
#define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \
|| (output_type) == oLatexDynamicModel \
|| (output_type) == oLatexDynamicSteadyStateOperator)
inline
bool
isMatlabOutput
(
ExprNodeOutputType
output_type
)
{
return
output_type
==
ExprNodeOutputType
::
matlabStaticModel
||
output_type
==
ExprNodeOutputType
::
matlabDynamicModel
||
output_type
==
ExprNodeOutputType
::
matlabOutsideModel
||
output_type
==
ExprNodeOutputType
::
matlabStaticModelSparse
||
output_type
==
ExprNodeOutputType
::
matlabDynamicModelSparse
||
output_type
==
ExprNodeOutputType
::
matlabDynamicSteadyStateOperator
||
output_type
==
ExprNodeOutputType
::
matlabDynamicSparseSteadyStateOperator
||
output_type
==
ExprNodeOutputType
::
steadyStateFile
||
output_type
==
ExprNodeOutputType
::
matlabDseries
||
output_type
==
ExprNodeOutputType
::
epilogueFile
;
}
inline
bool
isJuliaOutput
(
ExprNodeOutputType
output_type
)
{
return
output_type
==
ExprNodeOutputType
::
juliaStaticModel
||
output_type
==
ExprNodeOutputType
::
juliaDynamicModel
||
output_type
==
ExprNodeOutputType
::
juliaDynamicSteadyStateOperator
||
output_type
==
ExprNodeOutputType
::
juliaSteadyStateFile
;
}
inline
bool
isCOutput
(
ExprNodeOutputType
output_type
)
{
return
output_type
==
ExprNodeOutputType
::
CDynamicModel
||
output_type
==
ExprNodeOutputType
::
CStaticModel
||
output_type
==
ExprNodeOutputType
::
CDynamicSteadyStateOperator
;
}
inline
bool
isLatexOutput
(
ExprNodeOutputType
output_type
)
{
return
output_type
==
ExprNodeOutputType
::
latexStaticModel
||
output_type
==
ExprNodeOutputType
::
latexDynamicModel
||
output_type
==
ExprNodeOutputType
::
latexDynamicSteadyStateOperator
;
}
/* Equal to 1 for Matlab langage or Julia, or to 0 for C language. Not defined for LaTeX.
In Matlab and Julia, array indexes begin at 1, while they begin at 0 in C */
#define ARRAY_SUBSCRIPT_OFFSET(output_type) ((int) (
IS_MATLAB
(output_type) ||
IS_JULIA
(output_type)))
#define ARRAY_SUBSCRIPT_OFFSET(output_type) ((int) (
isMatlabOutput
(output_type) ||
isJuliaOutput
(output_type)))
// Left and right array subscript delimiters: '(' and ')' for Matlab, '[' and ']' for C
#define LEFT_ARRAY_SUBSCRIPT(output_type) (
IS_MATLAB
(output_type) ? '(' : '[')
#define RIGHT_ARRAY_SUBSCRIPT(output_type) (
IS_MATLAB
(output_type) ? ')' : ']')
#define LEFT_ARRAY_SUBSCRIPT(output_type) (
isMatlabOutput
(output_type) ? '(' : '[')
#define RIGHT_ARRAY_SUBSCRIPT(output_type) (
isMatlabOutput
(output_type) ? ')' : ']')
// Left and right parentheses
#define LEFT_PAR(output_type) (
IS_LATEX
(output_type) ? "\\left(" : "(")
#define RIGHT_PAR(output_type) (
IS_LATEX
(output_type) ? "\\right)" : ")")
#define LEFT_PAR(output_type) (
isLatexOutput
(output_type) ? "\\left(" : "(")
#define RIGHT_PAR(output_type) (
isLatexOutput
(output_type) ? "\\right)" : ")")
//! Base class for expression nodes
class
ExprNode
...
...
src/ModFile.cc
View file @
e19a1486
...
...
@@ -1009,19 +1009,19 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
auto
ivs
=
dynamic_cast
<
InitValStatement
*>
(
statement
.
get
());
if
(
ivs
!=
nullptr
)
{
static_model
.
writeAuxVarInitval
(
mOutputFile
,
oM
atlabOutsideModel
);
static_model
.
writeAuxVarInitval
(
mOutputFile
,
ExprNodeOutputType
::
m
atlabOutsideModel
);
ivs
->
writeOutputPostInit
(
mOutputFile
);
}
// Special treatment for endval block: insert initial values for the auxiliary variables
auto
evs
=
dynamic_cast
<
EndValStatement
*>
(
statement
.
get
());
if
(
evs
!=
nullptr
)
static_model
.
writeAuxVarInitval
(
mOutputFile
,
oM
atlabOutsideModel
);
static_model
.
writeAuxVarInitval
(
mOutputFile
,
ExprNodeOutputType
::
m
atlabOutsideModel
);
// Special treatment for load params and steady state statement: insert initial values for the auxiliary variables
auto
lpass
=
dynamic_cast
<
LoadParamsAndSteadyStateStatement
*>
(
statement
.
get
());
if
(
lpass
&&
!
no_static
)
static_model
.
writeAuxVarInitval
(
mOutputFile
,
oM
atlabOutsideModel
);
static_model
.
writeAuxVarInitval
(
mOutputFile
,
ExprNodeOutputType
::
m
atlabOutsideModel
);
}
mOutputFile
<<
"save('"
<<
basename
<<
"_results.mat', 'oo_', 'M_', 'options_');"
<<
endl
...
...
src/ModelEquationBlock.cc
View file @
e19a1486
...
...
@@ -147,7 +147,7 @@ SteadyStateModel::writeLatexSteadyStateFile(const string &basename) const
expr_t
value
=
it
.
second
;
content_output
<<
"
\\
begin{dmath}"
<<
endl
<<
symbol_table
.
getTeXName
(
id
)
<<
" = "
;
value
->
writeOutput
(
content_output
,
oL
atexStaticModel
);
value
->
writeOutput
(
content_output
,
ExprNodeOutputType
::
l
atexStaticModel
);
content_output
<<
endl
<<
"
\\
end{dmath}"
<<
endl
;
}
...
...
@@ -175,7 +175,7 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
exit
(
EXIT_FAILURE
);
}
ExprNodeOutputType
output_type
=
(
julia
?
oJ
uliaSteadyStateFile
:
oS
teadyStateFile
);
ExprNodeOutputType
output_type
=
(
julia
?
ExprNodeOutputType
::
j
uliaSteadyStateFile
:
ExprNodeOutputType
::
s
teadyStateFile
);
if
(
!
julia
)
output
<<
"function [ys_, params, info] = steadystate("
...
...
@@ -328,7 +328,7 @@ Epilogue::writeEpilogueFile(const string &basename) const
exit
(
EXIT_FAILURE
);
}
ExprNodeOutputType
output_type
=
o
EpilogueFile
;
ExprNodeOutputType
output_type
=
E
xprNodeOutputType
::
e
pilogueFile
;
output
<<
"function ds = epilogue(params, ds)"
<<
endl
<<
"% function ds = epilogue(params, ds)"
<<
endl
<<
"% Epilogue file generated by Dynare preprocessor"
<<
endl
<<
endl
...
...
src/ModelTree.cc
View file @
e19a1486
...
...
@@ -279,7 +279,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context, jacob_m
catch
(
ExprNode
::
EvalException
&
e
)
{
cerr
<<
"ERROR: evaluation of Jacobian failed for equation "
<<
eq
+
1
<<
" (line "
<<
equations_lineno
[
eq
]
<<
") and variable "
<<
symbol_table
.
getName
(
symb
)
<<
"("
<<
lag
<<
") ["
<<
symb
<<
"] !"
<<
endl
;
Id
->
writeOutput
(
cerr
,
oM
atlabDynamicModelSparse
,
temporary_terms
,
{});
Id
->
writeOutput
(
cerr
,
ExprNodeOutputType
::
m
atlabDynamicModelSparse
,
temporary_terms
,
{});
cerr
<<
endl
;
exit
(
EXIT_FAILURE
);
}
...
...
@@ -1193,16 +1193,16 @@ ModelTree::writeModelLocalVariableTemporaryTerms(const temporary_terms_t &tto, c
temporary_terms_t
tt2
;
for
(
auto
it
:
tt
)
{
if
(
IS_C
(
output_type
))
if
(
isCOutput
(
output_type
))
output
<<
"double "
;
else
if
(
IS_JULIA
(
output_type
))
else
if
(
isJuliaOutput
(
output_type
))
output
<<
" @inbounds const "
;
it
.
first
->
writeOutput
(
output
,
output_type
,
tto
,
temporary_terms_idxs
,
tef_terms
);
output
<<
" = "
;
it
.
second
->
writeOutput
(
output
,
output_type
,
tt2
,
temporary_terms_idxs
,
tef_terms
);
if
(
IS_C
(
output_type
)
||
IS_MATLAB
(
output_type
))
if
(
isCOutput
(
output_type
)
||
isMatlabOutput
(
output_type
))
output
<<
";"
;
output
<<
endl
;
...
...
@@ -1225,16 +1225,16 @@ ModelTree::writeTemporaryTerms(const temporary_terms_t &tt,
if
(
dynamic_cast
<
AbstractExternalFunctionNode
*>
(
*
it
)
!=
nullptr
)
(
*
it
)
->
writeExternalFunctionOutput
(
output
,
output_type
,
tt2
,
tt_idxs
,
tef_terms
);
if
(
IS_C
(
output_type
))
if
(
isCOutput
(
output_type
))
output
<<
"double "
;
else
if
(
IS_JULIA
(
output_type
))
else
if
(
isJuliaOutput
(
output_type
))
output
<<
" @inbounds "
;
(
*
it
)
->
writeOutput
(
output
,
output_type
,
tt
,
tt_idxs
,
tef_terms
);
output
<<
" = "
;
(
*
it
)
->
writeOutput
(
output
,
output_type
,
tt2
,
tt_idxs
,
tef_terms
);
if
(
IS_C
(
output_type
)
||
IS_MATLAB
(
output_type
))
if
(
isCOutput
(
output_type
)
||
isMatlabOutput
(
output_type
))
output
<<
";"
;
output
<<
endl
;
...
...
@@ -1527,7 +1527,7 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type,
}
if
(
vrhs
!=
0
)
// The right hand side of the equation is not empty ==> residual=lhs-rhs;
if
(
IS_JULIA
(
output_type
))
if
(
isJuliaOutput
(
output_type
))
{
output
<<
" @inbounds residual"
<<
LEFT_ARRAY_SUBSCRIPT
(
output_type
)
<<
eq
+
ARRAY_SUBSCRIPT_OFFSET
(
output_type
)
...
...
@@ -1553,7 +1553,7 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type,
}
else
// The right hand side of the equation is empty ==> residual=lhs;
{
if
(
IS_JULIA
(
output_type
))
if
(
isJuliaOutput
(
output_type
))
output
<<
" @inbounds "
;
output
<<
"residual"
<<
LEFT_ARRAY_SUBSCRIPT
(
output_type
)
<<
eq
+
ARRAY_SUBSCRIPT_OFFSET
(
output_type
)
...
...
@@ -1801,10 +1801,10 @@ ModelTree::set_cutoff_to_zero()
void
ModelTree
::
jacobianHelper
(
ostream
&
output
,
int
eq_nb
,
int
col_nb
,
ExprNodeOutputType
output_type
)
const
{
if
(
IS_JULIA
(
output_type
))
if
(
isJuliaOutput
(
output_type
))
output
<<
" @inbounds "
;
output
<<
"g1"
<<
LEFT_ARRAY_SUBSCRIPT
(
output_type
);
if
(
IS_MATLAB
(
output_type
)
||
IS_JULIA
(
output_type
))
if
(
isMatlabOutput
(
output_type
)
||
isJuliaOutput
(
output_type
))
output
<<
eq_nb
+
1
<<
","
<<
col_nb
+
1
;
else
output
<<
eq_nb
+
col_nb
*
equations
.
size
();
...
...
@@ -1815,7 +1815,7 @@ void
ModelTree
::
sparseHelper
(
int
order
,
ostream
&
output
,
int
row_nb
,
int
col_nb
,
ExprNodeOutputType
output_type
)
const
{
output
<<
"v"
<<
order
<<
LEFT_ARRAY_SUBSCRIPT
(
output_type
);
if
(
IS_MATLAB
(
output_type
)
||
IS_JULIA
(
output_type
))
if
(
isMatlabOutput
(
output_type
)
||
isJuliaOutput
(
output_type
))
output
<<
row_nb
+
1
<<
","
<<
col_nb
+
1
;
else
output
<<
row_nb
+
col_nb
*
NNZDerivatives
[
order
-
1
];
...
...
src/StaticModel.cc
View file @
e19a1486
...
...
@@ -203,7 +203,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &basename) const
deriv_node_temp_terms_t
tef_terms
;
ExprNodeOutputType
local_output_type
;
local_output_type
=
oM
atlabStaticModelSparse
;
local_output_type
=
ExprNodeOutputType
::
m
atlabStaticModelSparse
;
if
(
global_temporary_terms
)
local_temporary_terms
=
temporary_terms
;
...
...
@@ -1343,8 +1343,8 @@ StaticModel::writeStaticModel(const string &basename,
ostringstream
third_derivatives_output
;
// Used for storing third order derivatives equations
ostringstream
for_sym
;
ExprNodeOutputType
output_type
=
(
use_dll
?
o
CStaticModel
:
julia
?
oJuliaStaticModel
:
oM
atlabStaticModel
);
ExprNodeOutputType
output_type
=
(
use_dll
?
ExprNodeOutputType
::
CStaticModel
:
julia
?
ExprNodeOutputType
::
juliaStaticModel
:
ExprNodeOutputType
::
m
atlabStaticModel
);
deriv_node_temp_terms_t
tef_terms
;
temporary_terms_t
temp_term_union
;
...
...
@@ -1415,7 +1415,7 @@ StaticModel::writeStaticModel(const string &basename,
int
col_nb
=
tsid1
*
symbol_table
.
endo_nbr
()
+
tsid2
;
int
col_nb_sym
=
tsid2
*
symbol_table
.
endo_nbr
()
+
tsid1
;
if
(
output_type
==
oJ
uliaStaticModel
)
if
(
output_type
==
ExprNodeOutputType
::
j
uliaStaticModel
)
{
for_sym
<<
"g2["
<<
eq
+
1
<<
","
<<
col_nb
+
1
<<
"]"
;
hessian_output
<<
" @inbounds "
<<
for_sym
.
str
()
<<
" = "
;
...
...
@@ -1440,7 +1440,7 @@ StaticModel::writeStaticModel(const string &basename,
// Treating symetric elements
if
(
symb_id1
!=
symb_id2
)
if
(
output_type
==
oJ
uliaStaticModel
)
if
(
output_type
==
ExprNodeOutputType
::
j
uliaStaticModel
)
hessian_output
<<
" @inbounds g2["
<<
eq
+
1
<<
","
<<
col_nb_sym
+
1
<<
"] = "
<<
for_sym
.
str
()
<<
endl
;
else
...
...
@@ -1484,7 +1484,7 @@ StaticModel::writeStaticModel(const string &basename,
// Reference column number for the g3 matrix
int
ref_col
=
id1
*
hessianColsNbr
+
id2
*
JacobianColsNbr
+
id3
;
if
(
output_type
==
oJ
uliaStaticModel
)
if
(
output_type
==
ExprNodeOutputType
::
j
uliaStaticModel
)
{
for_sym
<<
"g3["
<<
eq
+
1
<<
","
<<
ref_col
+
1
<<
"]"
;
third_derivatives_output
<<
" @inbounds "
<<
for_sym
.
str
()
<<
" = "
;
...
...
@@ -1517,7 +1517,7 @@ StaticModel::writeStaticModel(const string &basename,
int
k2
=
1
;
// Keeps the offset of the permutation relative to k
for
(
int
col
:
cols
)
if
(
col
!=
ref_col
)
if
(
output_type
==
oJ
uliaStaticModel
)
if
(
output_type
==
ExprNodeOutputType
::
j
uliaStaticModel
)
third_derivatives_output
<<
" @inbounds g3["
<<
eq
+
1
<<
","
<<
col
+
1
<<
"] = "
<<
for_sym
.
str
()
<<
endl
;
else
...
...
@@ -1539,7 +1539,7 @@ StaticModel::writeStaticModel(const string &basename,
}
}
if
(
output_type
==
oM
atlabStaticModel
)
if
(
output_type
==
ExprNodeOutputType
::
m
atlabStaticModel
)
{
// Check that we don't have more than 32 nested parenthesis because Matlab does not suppor this. See Issue #1201
map
<
string
,
string
>
tmp_paren_vars
;
...
...
@@ -1619,7 +1619,7 @@ StaticModel::writeStaticModel(const string &basename,
writeStaticMatlabCompatLayer
(
basename
);
}
else
if
(
output_type
==
o
CStaticModel
)
else
if
(
output_type
==
ExprNodeOutputType
::
CStaticModel
)
{
StaticOutput
<<
"void Static(double *y, double *x, int nb_row_x, double *params, double *residual, double *g1, double *v2)"
<<
endl
<<
"{"
<<
endl
...
...
@@ -2351,7 +2351,7 @@ StaticModel::collect_block_first_order_derivatives()
void
StaticModel
::
writeLatexFile
(
const
string
&
basename
,
bool
write_equation_tags
)
const
{
writeLatexModelFile
(
basename
+
"_static"
,
oL
atexStaticModel
,
write_equation_tags
);
writeLatexModelFile
(
basename
+
"_static"
,
ExprNodeOutputType
::
l
atexStaticModel
,
write_equation_tags
);
}
void
...
...
@@ -2368,7 +2368,7 @@ void
StaticModel
::
writeSetAuxiliaryVariables
(
const
string
&
basename
,
const
bool
julia
)
const
{
ostringstream
output_func_body
;
writeAuxVarRecursiveDefinitions
(
output_func_body
,
oM
atlabStaticModel
);
writeAuxVarRecursiveDefinitions
(
output_func_body
,
ExprNodeOutputType
::
m
atlabStaticModel
);
if
(
output_func_body
.
str
().
empty
())
return
;
...
...
@@ -2402,7 +2402,7 @@ StaticModel::writeAuxVarRecursiveDefinitions(ostream &output, ExprNodeOutputType
deriv_node_temp_terms_t
tef_terms
;
for
(
auto
aux_equation
:
aux_equations
)
if
(
dynamic_cast
<
ExprNode
*>
(
aux_equation
)
->
containsExternalFunction
())
dynamic_cast
<
ExprNode
*>
(
aux_equation
)
->
writeExternalFunctionOutput
(
output
,
oM
atlabStaticModel
,
{},
{},
tef_terms
);
dynamic_cast
<
ExprNode
*>
(
aux_equation
)
->
writeExternalFunctionOutput
(
output
,
ExprNodeOutputType
::
m
atlabStaticModel
,
{},
{},
tef_terms
);
for
(
auto
aux_equation
:
aux_equations
)
{
dynamic_cast
<
ExprNode
*>
(
aux_equation
->
substituteStaticAuxiliaryDefinition
())
->
writeOutput
(
output
,
output_type
);
...
...
@@ -2418,12 +2418,12 @@ StaticModel::writeLatexAuxVarRecursiveDefinitions(ostream &output) const
temporary_terms_idxs_t
temporary_terms_idxs
;
for
(
auto
aux_equation
:
aux_equations
)
if
(
dynamic_cast
<
ExprNode
*>
(
aux_equation
)
->
containsExternalFunction
())
dynamic_cast
<
ExprNode
*>
(
aux_equation
)
->
writeExternalFunctionOutput
(
output
,
oL
atexStaticModel
,
dynamic_cast
<
ExprNode
*>
(
aux_equation
)
->
writeExternalFunctionOutput
(
output
,
ExprNodeOutputType
::
l
atexStaticModel
,
temporary_terms
,
temporary_terms_idxs
,
tef_terms
);
for
(
auto
aux_equation
:
aux_equations
)
{
output
<<
"
\\
begin{dmath}"
<<
endl
;
dynamic_cast
<
ExprNode
*>
(
aux_equation
->
substituteStaticAuxiliaryDefinition
())
->
writeOutput
(
output
,
oL
atexStaticModel
);
dynamic_cast
<
ExprNode
*>
(
aux_equation
->
substituteStaticAuxiliaryDefinition
())
->
writeOutput
(
output
,
ExprNodeOutputType
::
l
atexStaticModel
);
output
<<
endl
<<
"
\\
end{dmath}"
<<
endl
;
}
}
...
...
@@ -2470,7 +2470,7 @@ StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) cons
&&
!
hessian_params_derivatives
.
size
())
return
;
ExprNodeOutputType
output_type
=
(
julia
?
oJuliaStaticModel
:
oM
atlabStaticModel
);
ExprNodeOutputType
output_type
=
(
julia
?
ExprNodeOutputType
::
juliaStaticModel
:
ExprNodeOutputType
::
m
atlabStaticModel
);
ostringstream
model_local_vars_output
;
// Used for storing model local vars
ostringstream
model_output
;
// Used for storing model
...
...
src/SymbolTable.cc
View file @
e19a1486
...
...
@@ -371,7 +371,7 @@ SymbolTable::writeOutput(ostream &output) const noexcept(false)
output
<<
"M_.aux_vars("
<<
i
+
1
<<
").orig_expr = '
\\
mathbb{E}_{t"
<<
(
aux_vars
[
i
].
get_information_set
()
<
0
?
""
:
"+"
)
<<
aux_vars
[
i
].
get_information_set
()
<<
"}("
;
aux_vars
[
i
].
get_expr_node
()
->
writeOutput
(
output
,
oL
atexDynamicModel
);
aux_vars
[
i
].
get_expr_node
()
->
writeOutput
(
output
,
ExprNodeOutputType
::
l
atexDynamicModel
);
output
<<
")';"
<<
endl
;
break
;
case
AuxVarType
::
diff
:
...
...
@@ -1139,7 +1139,7 @@ SymbolTable::writeJuliaOutput(ostream &output) const noexcept(false)
output
<<
"typemin(Int), typemin(Int), typemin(Int),
\"\\
mathbb{E}_{t"
<<
(
aux_var
.
get_information_set
()
<
0
?
""
:
"+"
)
<<
aux_var
.
get_information_set
()
<<
"}("
;
aux_var
.
get_expr_node
()
->
writeOutput
(
output
,
oL
atexDynamicModel
);
aux_var
.
get_expr_node
()
->
writeOutput
(
output
,
ExprNodeOutputType
::
l
atexDynamicModel
);
output
<<
")
\"
"
;
break
;
default:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment