remove code that is no longer used in creation of auxiliary variables for diff operator

issue#70
Houtan Bastani 2018-05-31 18:44:06 +02:00
parent 1b952a12e6
commit 9166cda225
4 changed files with 6 additions and 144 deletions

View File

@ -3109,74 +3109,6 @@ UnaryOpNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table)
diff_table[sthis][arg_max_lag] = const_cast<UnaryOpNode *>(this);
}
void
UnaryOpNode::getDiffArgUnaryOperatorIfAny(string &op_handle) const
{
switch (op_code)
{
case oExp:
op_handle = "@exp";
break;
case oLog:
op_handle = "@log";
break;
case oLog10:
op_handle = "@log10";
break;
case oCos:
op_handle = "@cos";
break;
case oSin:
op_handle = "@sin";
break;
case oTan:
op_handle = "@tan";
break;
case oAcos:
op_handle = "@acos";
break;
case oAsin:
op_handle = "@asin";
break;
case oAtan:
op_handle = "@atan";
break;
case oCosh:
op_handle = "@cosh";
break;
case oSinh:
op_handle = "@sinh";
break;
case oTanh:
op_handle = "@tanh";
break;
case oAcosh:
op_handle = "@acosh";
break;
case oAsinh:
op_handle = "@asinh";
break;
case oAtanh:
op_handle = "@atanh";
break;
case oSqrt:
op_handle = "@sqrt";
break;
case oAbs:
op_handle = "@abs";
break;
case oSign:
op_handle = "@sign";
break;
case oErf:
op_handle = "@erf";
break;
default:
op_handle = "";
break;
}
}
expr_t
UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table,
vector<BinaryOpNode *> &neweqs) const
@ -3214,28 +3146,11 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table,
symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst, vn->get_symb_id(), vn->get_lag());
else
{
UnaryOpNode *diffarg = dynamic_cast<UnaryOpNode *>(argsubst);
if (diffarg != NULL)
{
string op;
diffarg->getDiffArgUnaryOperatorIfAny(op);
VariableNode *vnarg = dynamic_cast<VariableNode *>(diffarg->get_arg());
if (vnarg != NULL)
symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst,
vnarg->get_symb_id(), vnarg->get_lag(), op);
else
{
// The case where we have diff(log(exp(x))) for example
cerr << "diffs of nested non-diff expressions are not yet supported" << endl;
exit(EXIT_FAILURE);
}
}
else
{
cerr << "diffs of non unary expressions are not yet supported" << endl;
exit(EXIT_FAILURE);
}
// We know that the supported unary ops have already been substituted
cerr << "you can only use the `diff` operator on variables and certain unary ops" << endl;
exit(EXIT_FAILURE);
}
// make originating aux var & equation
last_arg_max_lag = rit->first;
last_aux_var = datatree.AddVariable(symb_id, 0);

View File

@ -790,7 +790,6 @@ public:
virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const;
bool createAuxVarForUnaryOpNodeInDiffOp() const;
virtual void findUnaryOpNodesForAuxVarCreation(DataTree &static_datatree, diff_table_t &nodes) const;
void getDiffArgUnaryOperatorIfAny(string &op_handle) const;
virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
virtual expr_t substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &nodes, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table);

View File

@ -25,20 +25,6 @@
#include "SymbolTable.hh"
AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg, int orig_lead_lag_arg,
int equation_number_for_multiplier_arg, int information_set_arg,
expr_t expr_node_arg, string &unary_op_handle_arg) :
symb_id(symb_id_arg),
type(type_arg),
orig_symb_id(orig_symb_id_arg),
orig_lead_lag(orig_lead_lag_arg),
equation_number_for_multiplier(equation_number_for_multiplier_arg),
information_set(information_set_arg),
expr_node(expr_node_arg),
unary_op_handle(unary_op_handle_arg)
{
}
AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg, int orig_lead_lag_arg,
int equation_number_for_multiplier_arg, int information_set_arg,
expr_t expr_node_arg) :
@ -48,8 +34,7 @@ AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg
orig_lead_lag(orig_lead_lag_arg),
equation_number_for_multiplier(equation_number_for_multiplier_arg),
information_set(information_set_arg),
expr_node(expr_node_arg),
unary_op_handle("")
expr_node(expr_node_arg)
{
}
@ -395,12 +380,6 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
if (aux_vars[i].get_orig_symb_id() >= 0)
output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl
<< "M_.aux_vars(" << i+1 << ").orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
output << "M_.aux_vars(" << i+1 << ").unary_op_handle = ";
if (!aux_vars[i].get_unary_op_handle().empty())
output << aux_vars[i].get_unary_op_handle() << ";" << endl;
else
output << "'';" << endl;
break;
}
}
@ -779,29 +758,6 @@ SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, i
return symb_id;
}
int
SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag, string &unary_op_handle) throw (FrozenException)
{
ostringstream varname;
int symb_id;
varname << "AUX_DIFF_" << index;
try
{
symb_id = addSymbol(varname.str(), eEndogenous);
}
catch (AlreadyDeclaredException &e)
{
cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
exit(EXIT_FAILURE);
}
aux_vars.push_back(AuxVarInfo(symb_id, avDiff, orig_symb_id, orig_lag, 0, 0, expr_arg, unary_op_handle));
return symb_id;
}
int
SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException)
{
@ -1166,7 +1122,7 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
case avDiffLag:
if (aux_vars[i].get_orig_symb_id() >= 0)
output << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) + 1 << ", "
<< aux_vars[i].get_orig_lead_lag() << ", NaN, NaN," << aux_vars[i].get_unary_op_handle();
<< aux_vars[i].get_orig_lead_lag() << ", NaN, NaN";
break;
case avMultiplier:
output << "NaN, NaN, " << aux_vars[i].get_equation_number_for_multiplier() + 1

View File

@ -60,10 +60,8 @@ private:
int equation_number_for_multiplier; //!< Stores the original constraint equation number associated with this aux var. Only used for avMultiplier.
int information_set; //! Argument of expectation operator. Only used for avExpectation.
expr_t expr_node; //! Auxiliary variable definition
string unary_op_handle; //!Unary op potentially opplied to aux vars of type avDiff
public:
AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id, int orig_lead_lag, int equation_number_for_multiplier_arg, int information_set_arg, expr_t expr_node_arg);
AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id, int orig_lead_lag, int equation_number_for_multiplier_arg, int information_set_arg, expr_t expr_node_arg, string &unary_op_handle);
int
get_symb_id() const
{
@ -99,11 +97,6 @@ public:
{
return expr_node;
};
string
get_unary_op_handle() const
{
return unary_op_handle;
}
};
//! Stores the symbol table
@ -298,7 +291,6 @@ public:
//! Adds an auxiliary variable when the diff operator is encountered
int addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException);
int addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) throw (FrozenException);
int addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag, string &unary_op_handle) throw (FrozenException);
//! Takes care of timing between diff statements
int addDiffLagAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) throw (FrozenException);
//! An Auxiliary variable for a unary op