Revert "Revert "preprocessor: allow for partitioning of variables along multiple dimensions""
This reverts commit b0e7f1cfd7d7b26305f6434de2869c1f19e8ff6d.issue#70
parent
24e25fd151
commit
db44b7337f
|
@ -53,6 +53,7 @@ class ParsingDriver;
|
||||||
vector<string *> *vector_string_val;
|
vector<string *> *vector_string_val;
|
||||||
vector<int> *vector_int_val;
|
vector<int> *vector_int_val;
|
||||||
pair<string *, string *> *string_pair_val;
|
pair<string *, string *> *string_pair_val;
|
||||||
|
vector<pair<string *, string *> *> *vector_string_pair_val;
|
||||||
PriorDistributions prior_distributions_val;
|
PriorDistributions prior_distributions_val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,7 +183,8 @@ class ParsingDriver;
|
||||||
%type <string_val> vec_value_1 vec_value signed_inf signed_number_w_inf
|
%type <string_val> vec_value_1 vec_value signed_inf signed_number_w_inf
|
||||||
%type <string_val> range vec_value_w_inf vec_value_1_w_inf
|
%type <string_val> range vec_value_w_inf vec_value_1_w_inf
|
||||||
%type <string_val> integer_range signed_integer_range sub_sampling_options list_sub_sampling_option
|
%type <string_val> integer_range signed_integer_range sub_sampling_options list_sub_sampling_option
|
||||||
%type <string_pair_val> named_var
|
%type <string_pair_val> named_var_elem
|
||||||
|
%type <vector_string_pair_val> named_var named_var_1
|
||||||
%type <symbol_type_val> change_type_arg
|
%type <symbol_type_val> change_type_arg
|
||||||
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt calibration_range
|
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt calibration_range
|
||||||
%type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number
|
%type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number
|
||||||
|
@ -375,11 +377,36 @@ predetermined_variables : PREDETERMINED_VARIABLES predetermined_variables_list '
|
||||||
|
|
||||||
parameters : PARAMETERS parameter_list ';';
|
parameters : PARAMETERS parameter_list ';';
|
||||||
|
|
||||||
named_var : '(' symbol EQUAL QUOTED_STRING ')'
|
named_var_elem : symbol EQUAL QUOTED_STRING
|
||||||
{
|
{
|
||||||
pair<string *, string *> *pr = new pair<string *, string *>($2, $4);
|
pair<string *, string *> *pr = new pair<string *, string *>($1, $3);
|
||||||
$$ = pr;
|
$$ = pr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
named_var_1 : '(' named_var_elem
|
||||||
|
{
|
||||||
|
$$ = new vector<pair<string *, string *> *>();
|
||||||
|
$$->push_back($2);
|
||||||
|
}
|
||||||
|
| '(' COMMA named_var_elem
|
||||||
|
{
|
||||||
|
$$ = new vector<pair<string *, string *> *>();
|
||||||
|
$$->push_back($3);
|
||||||
|
}
|
||||||
|
| named_var_1 named_var_elem
|
||||||
|
{
|
||||||
|
$1->push_back($2);
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| named_var_1 COMMA named_var_elem
|
||||||
|
{
|
||||||
|
$1->push_back($3);
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
named_var : named_var_1 ')' { $$ = $1; }
|
||||||
|
| named_var_1 COMMA ')' { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
var_list : var_list symbol
|
var_list : var_list symbol
|
||||||
|
|
|
@ -132,7 +132,7 @@ ParsingDriver::warning(const string &m)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_symbol(const string *name, SymbolType type, const string *tex_name, const pair<string *, string *> *partition_value)
|
ParsingDriver::declare_symbol(const string *name, SymbolType type, const string *tex_name, const vector<pair<string *, string *> *> *partition_value)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -156,7 +156,7 @@ ParsingDriver::declare_symbol(const string *name, SymbolType type, const string
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_endogenous(string *name, string *tex_name, pair<string *, string *> *partition_value)
|
ParsingDriver::declare_endogenous(string *name, string *tex_name, vector<pair<string *, string *> *> *partition_value)
|
||||||
{
|
{
|
||||||
declare_symbol(name, eEndogenous, tex_name, partition_value);
|
declare_symbol(name, eEndogenous, tex_name, partition_value);
|
||||||
delete name;
|
delete name;
|
||||||
|
@ -164,14 +164,19 @@ ParsingDriver::declare_endogenous(string *name, string *tex_name, pair<string *,
|
||||||
delete tex_name;
|
delete tex_name;
|
||||||
if (partition_value != NULL)
|
if (partition_value != NULL)
|
||||||
{
|
{
|
||||||
delete partition_value->first;
|
for (vector<pair<string *, string *> *>::iterator it = partition_value->begin();
|
||||||
delete partition_value->second;
|
it != partition_value->end(); ++it)
|
||||||
|
{
|
||||||
|
delete (*it)->first;
|
||||||
|
delete (*it)->second;
|
||||||
|
delete (*it);
|
||||||
|
}
|
||||||
delete partition_value;
|
delete partition_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_exogenous(string *name, string *tex_name, pair<string *, string *> *partition_value)
|
ParsingDriver::declare_exogenous(string *name, string *tex_name, vector<pair<string *, string *> *> *partition_value)
|
||||||
{
|
{
|
||||||
declare_symbol(name, eExogenous, tex_name, partition_value);
|
declare_symbol(name, eExogenous, tex_name, partition_value);
|
||||||
delete name;
|
delete name;
|
||||||
|
@ -179,14 +184,19 @@ ParsingDriver::declare_exogenous(string *name, string *tex_name, pair<string *,
|
||||||
delete tex_name;
|
delete tex_name;
|
||||||
if (partition_value != NULL)
|
if (partition_value != NULL)
|
||||||
{
|
{
|
||||||
delete partition_value->first;
|
for (vector<pair<string *, string *> *>::iterator it = partition_value->begin();
|
||||||
delete partition_value->second;
|
it != partition_value->end(); ++it)
|
||||||
|
{
|
||||||
|
delete (*it)->first;
|
||||||
|
delete (*it)->second;
|
||||||
|
delete (*it);
|
||||||
|
}
|
||||||
delete partition_value;
|
delete partition_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_exogenous_det(string *name, string *tex_name, pair<string *, string *> *partition_value)
|
ParsingDriver::declare_exogenous_det(string *name, string *tex_name, vector<pair<string *, string *> *> *partition_value)
|
||||||
{
|
{
|
||||||
declare_symbol(name, eExogenousDet, tex_name, partition_value);
|
declare_symbol(name, eExogenousDet, tex_name, partition_value);
|
||||||
delete name;
|
delete name;
|
||||||
|
@ -194,14 +204,19 @@ ParsingDriver::declare_exogenous_det(string *name, string *tex_name, pair<string
|
||||||
delete tex_name;
|
delete tex_name;
|
||||||
if (partition_value != NULL)
|
if (partition_value != NULL)
|
||||||
{
|
{
|
||||||
delete partition_value->first;
|
for (vector<pair<string *, string *> *>::iterator it = partition_value->begin();
|
||||||
delete partition_value->second;
|
it != partition_value->end(); ++it)
|
||||||
|
{
|
||||||
|
delete (*it)->first;
|
||||||
|
delete (*it)->second;
|
||||||
|
delete (*it);
|
||||||
|
}
|
||||||
delete partition_value;
|
delete partition_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_parameter(string *name, string *tex_name, pair<string *, string *> *partition_value)
|
ParsingDriver::declare_parameter(string *name, string *tex_name, vector<pair<string *, string *> *> *partition_value)
|
||||||
{
|
{
|
||||||
declare_symbol(name, eParameter, tex_name, partition_value);
|
declare_symbol(name, eParameter, tex_name, partition_value);
|
||||||
delete name;
|
delete name;
|
||||||
|
@ -209,8 +224,13 @@ ParsingDriver::declare_parameter(string *name, string *tex_name, pair<string *,
|
||||||
delete tex_name;
|
delete tex_name;
|
||||||
if (partition_value != NULL)
|
if (partition_value != NULL)
|
||||||
{
|
{
|
||||||
delete partition_value->first;
|
for (vector<pair<string *, string *> *>::iterator it = partition_value->begin();
|
||||||
delete partition_value->second;
|
it != partition_value->end(); ++it)
|
||||||
|
{
|
||||||
|
delete (*it)->first;
|
||||||
|
delete (*it)->second;
|
||||||
|
delete (*it);
|
||||||
|
}
|
||||||
delete partition_value;
|
delete partition_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,7 +391,7 @@ ParsingDriver::add_expression_variable(string *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParsingDriver::declare_nonstationary_var(string *name, string *tex_name, pair<string *, string *> *partition_value)
|
ParsingDriver::declare_nonstationary_var(string *name, string *tex_name, vector<pair<string *, string *> *> *partition_value)
|
||||||
{
|
{
|
||||||
if (tex_name == NULL && partition_value == NULL)
|
if (tex_name == NULL && partition_value == NULL)
|
||||||
declare_endogenous(new string(*name));
|
declare_endogenous(new string(*name));
|
||||||
|
|
|
@ -94,7 +94,7 @@ private:
|
||||||
void check_symbol_is_endogenous_or_exogenous(string *name);
|
void check_symbol_is_endogenous_or_exogenous(string *name);
|
||||||
|
|
||||||
//! Helper to add a symbol declaration
|
//! Helper to add a symbol declaration
|
||||||
void declare_symbol(const string *name, SymbolType type, const string *tex_name, const pair<string *, string *> *partition_value);
|
void declare_symbol(const string *name, SymbolType type, const string *tex_name, const vector<pair<string *, string *> *> *partition_value);
|
||||||
|
|
||||||
//! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name
|
//! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name
|
||||||
void optim_options_helper(const string &name);
|
void optim_options_helper(const string &name);
|
||||||
|
@ -277,13 +277,13 @@ public:
|
||||||
//! Sets the FILENAME for the initial value in initval
|
//! Sets the FILENAME for the initial value in initval
|
||||||
void initval_file(string *filename);
|
void initval_file(string *filename);
|
||||||
//! Declares an endogenous variable
|
//! Declares an endogenous variable
|
||||||
void declare_endogenous(string *name, string *tex_name = NULL, pair<string *, string *> *partition_value = NULL);
|
void declare_endogenous(string *name, string *tex_name = NULL, vector<pair<string *, string *> *> *partition_value = NULL);
|
||||||
//! Declares an exogenous variable
|
//! Declares an exogenous variable
|
||||||
void declare_exogenous(string *name, string *tex_name = NULL, pair<string *, string *> *partition_value = NULL);
|
void declare_exogenous(string *name, string *tex_name = NULL, vector<pair<string *, string *> *> *partition_value = NULL);
|
||||||
//! Declares an exogenous deterministic variable
|
//! Declares an exogenous deterministic variable
|
||||||
void declare_exogenous_det(string *name, string *tex_name = NULL, pair<string *, string *> *partition_value = NULL);
|
void declare_exogenous_det(string *name, string *tex_name = NULL, vector<pair<string *, string *> *> *partition_value = NULL);
|
||||||
//! Declares a parameter
|
//! Declares a parameter
|
||||||
void declare_parameter(string *name, string *tex_name = NULL, pair<string *, string *> *partition_value = NULL);
|
void declare_parameter(string *name, string *tex_name = NULL, vector<pair<string *, string *> *> *partition_value = NULL);
|
||||||
//! Declares a statement local variable
|
//! Declares a statement local variable
|
||||||
void declare_statement_local_variable(string *name);
|
void declare_statement_local_variable(string *name);
|
||||||
//! Completes a subsample statement
|
//! Completes a subsample statement
|
||||||
|
@ -692,7 +692,7 @@ public:
|
||||||
//! Ends declaration of trend variable
|
//! Ends declaration of trend variable
|
||||||
void end_trend_var(expr_t growth_factor);
|
void end_trend_var(expr_t growth_factor);
|
||||||
//! Declares a nonstationary variable with its deflator
|
//! Declares a nonstationary variable with its deflator
|
||||||
void declare_nonstationary_var(string *name, string *tex_name = NULL, pair<string *, string *> *partition_value = NULL);
|
void declare_nonstationary_var(string *name, string *tex_name = NULL, vector<pair<string *, string *> *> *partition_value = NULL);
|
||||||
//! Ends declaration of nonstationary variable
|
//! Ends declaration of nonstationary variable
|
||||||
void end_nonstationary_var(bool log_deflator, expr_t deflator);
|
void end_nonstationary_var(bool log_deflator, expr_t deflator);
|
||||||
//! Add a graph format to the list of formats requested
|
//! Add a graph format to the list of formats requested
|
||||||
|
|
200
SymbolTable.cc
200
SymbolTable.cc
|
@ -42,7 +42,7 @@ SymbolTable::SymbolTable() : frozen(false), size(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name, const pair<string * , string *> *partition_value) throw (AlreadyDeclaredException, FrozenException)
|
SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name, const vector<pair<string * , string *> *> *partition_value) throw (AlreadyDeclaredException, FrozenException)
|
||||||
{
|
{
|
||||||
if (frozen)
|
if (frozen)
|
||||||
throw FrozenException();
|
throw FrozenException();
|
||||||
|
@ -67,11 +67,15 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string final_long_name;
|
string final_long_name = name;
|
||||||
if (partition_value == NULL || *(partition_value->first) != "long_name")
|
bool non_long_name_partition_exists = false;
|
||||||
final_long_name = name;
|
if (partition_value)
|
||||||
else
|
for (vector<pair<string *, string *> *>::const_iterator it = partition_value->begin();
|
||||||
final_long_name = *(partition_value->second);
|
it != partition_value->end(); it++)
|
||||||
|
if (*((*it)->first) == "long_name")
|
||||||
|
final_long_name = *((*it)->second);
|
||||||
|
else
|
||||||
|
non_long_name_partition_exists = true;
|
||||||
|
|
||||||
int id = size++;
|
int id = size++;
|
||||||
|
|
||||||
|
@ -80,9 +84,14 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
|
||||||
name_table.push_back(name);
|
name_table.push_back(name);
|
||||||
tex_name_table.push_back(final_tex_name);
|
tex_name_table.push_back(final_tex_name);
|
||||||
long_name_table.push_back(final_long_name);
|
long_name_table.push_back(final_long_name);
|
||||||
if (partition_value && *(partition_value->first) != "long_name")
|
if (non_long_name_partition_exists)
|
||||||
partition_value_map[id] = pair<string *, string *>(new string(partition_value->first->c_str()),
|
{
|
||||||
new string(partition_value->second->c_str()));
|
map<string, string> pmv;
|
||||||
|
for (vector<pair<string *, string *> *>::const_iterator it = partition_value->begin();
|
||||||
|
it != partition_value->end(); it++)
|
||||||
|
pmv[*((*it)->first)] = *((*it)->second);
|
||||||
|
partition_value_map[id] = pmv;
|
||||||
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,21 +183,21 @@ SymbolTable::getID(SymbolType type, int tsid) const throw (UnknownTypeSpecificID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
map<string, map<int, string> >
|
||||||
SymbolTable::isFirstOfPartitionForType(int id) const throw (UnknownSymbolIDException)
|
SymbolTable::getPartitionsForType(enum SymbolType st) const throw (UnknownSymbolIDException)
|
||||||
{
|
{
|
||||||
if (id < 0 || id >= size || !hasPartition(id))
|
map<string, map<int, string> > partitions;
|
||||||
throw UnknownSymbolIDException(id);
|
for (map<int, map<string, string> >::const_iterator it = partition_value_map.begin();
|
||||||
|
|
||||||
string partition_name = getPartition(id);
|
|
||||||
SymbolType st = getType(id);
|
|
||||||
for (map<int, pair<string *, string * > >::const_iterator it = partition_value_map.begin();
|
|
||||||
it != partition_value_map.end(); it++)
|
it != partition_value_map.end(); it++)
|
||||||
if (st == getType(it->first) &&
|
if (getType(it->first) == st)
|
||||||
it->first < id &&
|
for (map<string, string>::const_iterator it1 = it->second.begin();
|
||||||
partition_name == *(it->second.first))
|
it1 != it->second.end(); it1++)
|
||||||
return false;
|
{
|
||||||
return true;
|
if (partitions.find(it1->first) == partitions.end())
|
||||||
|
partitions[it1->first] = map<int, string> ();
|
||||||
|
partitions[it1->first][it->first] = it1->second;
|
||||||
|
}
|
||||||
|
return partitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -202,23 +211,29 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
|
||||||
output << "M_.exo_names = '" << getName(exo_ids[0]) << "';" << endl;
|
output << "M_.exo_names = '" << getName(exo_ids[0]) << "';" << endl;
|
||||||
output << "M_.exo_names_tex = '" << getTeXName(exo_ids[0]) << "';" << endl;
|
output << "M_.exo_names_tex = '" << getTeXName(exo_ids[0]) << "';" << endl;
|
||||||
output << "M_.exo_names_long = '" << getLongName(exo_ids[0]) << "';" << endl;
|
output << "M_.exo_names_long = '" << getLongName(exo_ids[0]) << "';" << endl;
|
||||||
if (hasPartition(exo_ids[0]))
|
|
||||||
output << "M_.exo_" << getPartition(exo_ids[0]) << " = '"
|
|
||||||
<< getPartitionValue(exo_ids[0]) << "';" << endl;
|
|
||||||
for (int id = 1; id < exo_nbr(); id++)
|
for (int id = 1; id < exo_nbr(); id++)
|
||||||
{
|
output << "M_.exo_names = char(M_.exo_names, '" << getName(exo_ids[id]) << "');" << endl
|
||||||
output << "M_.exo_names = char(M_.exo_names, '" << getName(exo_ids[id]) << "');" << endl
|
<< "M_.exo_names_tex = char(M_.exo_names_tex, '" << getTeXName(exo_ids[id]) << "');" << endl
|
||||||
<< "M_.exo_names_tex = char(M_.exo_names_tex, '" << getTeXName(exo_ids[id]) << "');" << endl
|
<< "M_.exo_names_long = char(M_.exo_names_long, '" << getLongName(exo_ids[id]) << "');" << endl;
|
||||||
<< "M_.exo_names_long = char(M_.exo_names_long, '" << getLongName(exo_ids[id]) << "');" << endl;
|
|
||||||
if (hasPartition(exo_ids[id]))
|
|
||||||
if (isFirstOfPartitionForType(exo_ids[id]))
|
map<string, map<int, string> > partitions = getPartitionsForType(eExogenous);
|
||||||
output << "M_.exo_" << getPartition(exo_ids[id]) << " = '"
|
for (map<string, map<int, string> >::const_iterator it = partitions.begin();
|
||||||
<< getPartitionValue(exo_ids[id]) << "';" << endl;
|
it != partitions.end(); it++)
|
||||||
else
|
if (it->first != "long_name")
|
||||||
output << "M_.exo_" << getPartition(exo_ids[id]) << " = "
|
{
|
||||||
<< "char(M_.exo_" << getPartition(exo_ids[id]) << ", '"
|
map<int, string>::const_iterator it1;
|
||||||
<< getPartitionValue(exo_ids[id]) << "');" << endl;
|
output << "M_.exo_partitions." << it->first << " = { ";
|
||||||
}
|
for (int id = 0; id < exo_nbr(); id++)
|
||||||
|
{
|
||||||
|
output << "'";
|
||||||
|
it1 = it->second.find(exo_ids[id]);
|
||||||
|
if (it1 != it->second.end())
|
||||||
|
output << it1->second;
|
||||||
|
output << "' ";
|
||||||
|
}
|
||||||
|
output << "};" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exo_det_nbr() > 0)
|
if (exo_det_nbr() > 0)
|
||||||
|
@ -226,23 +241,29 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
|
||||||
output << "M_.exo_det_names = '" << getName(exo_det_ids[0]) << "';" << endl;
|
output << "M_.exo_det_names = '" << getName(exo_det_ids[0]) << "';" << endl;
|
||||||
output << "M_.exo_det_names_tex = '" << getTeXName(exo_det_ids[0]) << "';" << endl;
|
output << "M_.exo_det_names_tex = '" << getTeXName(exo_det_ids[0]) << "';" << endl;
|
||||||
output << "M_.exo_det_names_long = '" << getLongName(exo_det_ids[0]) << "';" << endl;
|
output << "M_.exo_det_names_long = '" << getLongName(exo_det_ids[0]) << "';" << endl;
|
||||||
if (hasPartition(exo_det_ids[0]))
|
|
||||||
output << "M_.exo_det_" << getPartition(exo_det_ids[0]) << " = '"
|
|
||||||
<< getPartitionValue(exo_det_ids[0]) << "';" << endl;
|
|
||||||
for (int id = 1; id < exo_det_nbr(); id++)
|
for (int id = 1; id < exo_det_nbr(); id++)
|
||||||
{
|
output << "M_.exo_det_names = char(M_.exo_det_names, '" << getName(exo_det_ids[id]) << "');" << endl
|
||||||
output << "M_.exo_det_names = char(M_.exo_det_names, '" << getName(exo_det_ids[id]) << "');" << endl
|
<< "M_.exo_det_names_tex = char(M_.exo_det_names_tex, '" << getTeXName(exo_det_ids[id]) << "');" << endl
|
||||||
<< "M_.exo_det_names_tex = char(M_.exo_det_names_tex, '" << getTeXName(exo_det_ids[id]) << "');" << endl
|
<< "M_.exo_det_names_long = char(M_.exo_det_names_long, '" << getLongName(exo_det_ids[id]) << "');" << endl;
|
||||||
<< "M_.exo_det_names_long = char(M_.exo_det_names_long, '" << getLongName(exo_det_ids[id]) << "');" << endl;
|
|
||||||
if (hasPartition(exo_det_ids[id]))
|
output << "M_.exo_det_partitions = struct();" << endl;
|
||||||
if (isFirstOfPartitionForType(exo_det_ids[id]))
|
map<string, map<int, string> > partitions = getPartitionsForType(eExogenousDet);
|
||||||
output << "M_.exo_det_" << getPartition(exo_det_ids[id]) << " = '"
|
for (map<string, map<int, string> >::const_iterator it = partitions.begin();
|
||||||
<< getPartitionValue(exo_det_ids[id]) << "';" << endl;
|
it != partitions.end(); it++)
|
||||||
else
|
if (it->first != "long_name")
|
||||||
output << "M_.exo_det_" << getPartition(exo_det_ids[id]) << " = "
|
{
|
||||||
<< "char(M_.exo_det_" << getPartition(exo_det_ids[id]) << ", '"
|
map<int, string>::const_iterator it1;
|
||||||
<< getPartitionValue(exo_det_ids[id]) << "');" << endl;
|
output << "M_.exo_det_partitions." << it->first << " = { ";
|
||||||
}
|
for (int id = 0; id < exo_det_nbr(); id++)
|
||||||
|
{
|
||||||
|
output << "'";
|
||||||
|
it1 = it->second.find(exo_det_ids[id]);
|
||||||
|
if (it1 != it->second.end())
|
||||||
|
output << it1->second;
|
||||||
|
output << "' ";
|
||||||
|
}
|
||||||
|
output << "};" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endo_nbr() > 0)
|
if (endo_nbr() > 0)
|
||||||
|
@ -250,24 +271,29 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
|
||||||
output << "M_.endo_names = '" << getName(endo_ids[0]) << "';" << endl;
|
output << "M_.endo_names = '" << getName(endo_ids[0]) << "';" << endl;
|
||||||
output << "M_.endo_names_tex = '" << getTeXName(endo_ids[0]) << "';" << endl;
|
output << "M_.endo_names_tex = '" << getTeXName(endo_ids[0]) << "';" << endl;
|
||||||
output << "M_.endo_names_long = '" << getLongName(endo_ids[0]) << "';" << endl;
|
output << "M_.endo_names_long = '" << getLongName(endo_ids[0]) << "';" << endl;
|
||||||
if (hasPartition(endo_ids[0]))
|
|
||||||
output << "M_.endo_" << getPartition(endo_ids[0]) << " = '"
|
|
||||||
<< getPartitionValue(endo_ids[0]) << "';" << endl;
|
|
||||||
|
|
||||||
for (int id = 1; id < endo_nbr(); id++)
|
for (int id = 1; id < endo_nbr(); id++)
|
||||||
{
|
output << "M_.endo_names = char(M_.endo_names, '" << getName(endo_ids[id]) << "');" << endl
|
||||||
output << "M_.endo_names = char(M_.endo_names, '" << getName(endo_ids[id]) << "');" << endl
|
<< "M_.endo_names_tex = char(M_.endo_names_tex, '" << getTeXName(endo_ids[id]) << "');" << endl
|
||||||
<< "M_.endo_names_tex = char(M_.endo_names_tex, '" << getTeXName(endo_ids[id]) << "');" << endl
|
<< "M_.endo_names_long = char(M_.endo_names_long, '" << getLongName(endo_ids[id]) << "');" << endl;
|
||||||
<< "M_.endo_names_long = char(M_.endo_names_long, '" << getLongName(endo_ids[id]) << "');" << endl;
|
|
||||||
if (hasPartition(endo_ids[id]))
|
output << "M_.endo_partitions = struct();" << endl;
|
||||||
if (isFirstOfPartitionForType(endo_ids[id]))
|
map<string, map<int, string> > partitions = getPartitionsForType(eEndogenous);
|
||||||
output << "M_.endo_" << getPartition(endo_ids[id]) << " = '"
|
for (map<string, map<int, string> >::const_iterator it = partitions.begin();
|
||||||
<< getPartitionValue(endo_ids[id]) << "';" << endl;
|
it != partitions.end(); it++)
|
||||||
else
|
if (it->first != "long_name")
|
||||||
output << "M_.endo_" << getPartition(endo_ids[id]) << " = "
|
{
|
||||||
<< "char(M_.endo_" << getPartition(endo_ids[id]) << ", '"
|
map<int, string>::const_iterator it1;
|
||||||
<< getPartitionValue(endo_ids[id]) << "');" << endl;
|
output << "M_.endo_partitions." << it->first << " = { ";
|
||||||
}
|
for (int id = 0; id < endo_nbr(); id++)
|
||||||
|
{
|
||||||
|
output << "'";
|
||||||
|
it1 = it->second.find(endo_ids[id]);
|
||||||
|
if (it1 != it->second.end())
|
||||||
|
output << it1->second;
|
||||||
|
output << "' ";
|
||||||
|
}
|
||||||
|
output << "};" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param_nbr() > 0)
|
if (param_nbr() > 0)
|
||||||
|
@ -275,10 +301,6 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
|
||||||
output << "M_.param_names = '" << getName(param_ids[0]) << "';" << endl;
|
output << "M_.param_names = '" << getName(param_ids[0]) << "';" << endl;
|
||||||
output << "M_.param_names_tex = '" << getTeXName(param_ids[0]) << "';" << endl;
|
output << "M_.param_names_tex = '" << getTeXName(param_ids[0]) << "';" << endl;
|
||||||
output << "M_.param_names_long = '" << getLongName(param_ids[0]) << "';" << endl;
|
output << "M_.param_names_long = '" << getLongName(param_ids[0]) << "';" << endl;
|
||||||
if (hasPartition(param_ids[0]))
|
|
||||||
output << "M_.param_" << getPartition(param_ids[0]) << " = '"
|
|
||||||
<< getPartitionValue(param_ids[0]) << "';" << endl;
|
|
||||||
|
|
||||||
for (int id = 1; id < param_nbr(); id++)
|
for (int id = 1; id < param_nbr(); id++)
|
||||||
{
|
{
|
||||||
output << "M_.param_names = char(M_.param_names, '" << getName(param_ids[id]) << "');" << endl
|
output << "M_.param_names = char(M_.param_names, '" << getName(param_ids[id]) << "');" << endl
|
||||||
|
@ -287,16 +309,26 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
|
||||||
|
|
||||||
if (getName(param_ids[id]) == "dsge_prior_weight")
|
if (getName(param_ids[id]) == "dsge_prior_weight")
|
||||||
output << "options_.dsge_var = 1;" << endl;
|
output << "options_.dsge_var = 1;" << endl;
|
||||||
|
|
||||||
if (hasPartition(param_ids[id]))
|
|
||||||
if (isFirstOfPartitionForType(param_ids[id]))
|
|
||||||
output << "M_.param_" << getPartition(param_ids[id]) << " = '"
|
|
||||||
<< getPartitionValue(param_ids[id]) << "';" << endl;
|
|
||||||
else
|
|
||||||
output << "M_.param_" << getPartition(param_ids[id]) << " = "
|
|
||||||
<< "char(M_.param_" << getPartition(param_ids[id]) << ", '"
|
|
||||||
<< getPartitionValue(param_ids[id]) << "');" << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output << "M_.param_partitions = struct();" << endl;
|
||||||
|
map<string, map<int, string> > partitions = getPartitionsForType(eParameter);
|
||||||
|
for (map<string, map<int, string> >::const_iterator it = partitions.begin();
|
||||||
|
it != partitions.end(); it++)
|
||||||
|
if (it->first != "long_name")
|
||||||
|
{
|
||||||
|
map<int, string>::const_iterator it1;
|
||||||
|
output << "M_.param_partitions." << it->first << " = { ";
|
||||||
|
for (int id = 0; id < param_nbr(); id++)
|
||||||
|
{
|
||||||
|
output << "'";
|
||||||
|
it1 = it->second.find(param_ids[id]);
|
||||||
|
if (it1 != it->second.end())
|
||||||
|
output << it1->second;
|
||||||
|
output << "' ";
|
||||||
|
}
|
||||||
|
output << "};" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output << "M_.exo_det_nbr = " << exo_det_nbr() << ";" << endl
|
output << "M_.exo_det_nbr = " << exo_det_nbr() << ";" << endl
|
||||||
|
|
|
@ -97,7 +97,7 @@ private:
|
||||||
//! Maps IDs to string names of variables
|
//! Maps IDs to string names of variables
|
||||||
vector<string> long_name_table;
|
vector<string> long_name_table;
|
||||||
//! Maps IDs to a pair containing the partition and the partition value
|
//! Maps IDs to a pair containing the partition and the partition value
|
||||||
map<int, pair<string *, string * > > partition_value_map;
|
map<int, map<string, string> > partition_value_map;
|
||||||
//! Maps IDs to types
|
//! Maps IDs to types
|
||||||
vector<SymbolType> type_table;
|
vector<SymbolType> type_table;
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ private:
|
||||||
public:
|
public:
|
||||||
//! Add a symbol
|
//! Add a symbol
|
||||||
/*! Returns the symbol ID */
|
/*! Returns the symbol ID */
|
||||||
int addSymbol(const string &name, SymbolType type, const string &tex_name, const pair<string *, string *> *partition_value) throw (AlreadyDeclaredException, FrozenException);
|
int addSymbol(const string &name, SymbolType type, const string &tex_name, const vector<pair<string *, string *> *> *partition_value) throw (AlreadyDeclaredException, FrozenException);
|
||||||
//! Add a symbol without its TeX name (will be equal to its name)
|
//! Add a symbol without its TeX name (will be equal to its name)
|
||||||
/*! Returns the symbol ID */
|
/*! Returns the symbol ID */
|
||||||
int addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException);
|
int addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException);
|
||||||
|
@ -260,14 +260,10 @@ public:
|
||||||
inline string getTeXName(int id) const throw (UnknownSymbolIDException);
|
inline string getTeXName(int id) const throw (UnknownSymbolIDException);
|
||||||
//! Get long name
|
//! Get long name
|
||||||
inline string getLongName(int id) const throw (UnknownSymbolIDException);
|
inline string getLongName(int id) const throw (UnknownSymbolIDException);
|
||||||
//! Has partition
|
|
||||||
inline bool hasPartition(int id) const throw (UnknownSymbolIDException);
|
|
||||||
//! Returns true if the partition name is the first encountered for the type of variable represented by id
|
//! Returns true if the partition name is the first encountered for the type of variable represented by id
|
||||||
bool isFirstOfPartitionForType(int id) const throw (UnknownSymbolIDException);
|
bool isFirstOfPartitionForType(int id) const throw (UnknownSymbolIDException);
|
||||||
//! Get partition
|
//! Returns a list of partitions and symbols that belong to that partition
|
||||||
inline string getPartition(int id) const throw (UnknownSymbolIDException);
|
map<string, map<int, string> > getPartitionsForType(enum SymbolType st) const throw (UnknownSymbolIDException);
|
||||||
//! Get partition value
|
|
||||||
inline string getPartitionValue(int id) const throw (UnknownSymbolIDException);
|
|
||||||
//! Get type (by ID)
|
//! Get type (by ID)
|
||||||
inline SymbolType getType(int id) const throw (UnknownSymbolIDException);
|
inline SymbolType getType(int id) const throw (UnknownSymbolIDException);
|
||||||
//! Get type (by name)
|
//! Get type (by name)
|
||||||
|
@ -365,33 +361,6 @@ SymbolTable::getLongName(int id) const throw (UnknownSymbolIDException)
|
||||||
return long_name_table[id];
|
return long_name_table[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
|
||||||
SymbolTable::hasPartition(int id) const throw (UnknownSymbolIDException)
|
|
||||||
{
|
|
||||||
if (id < 0 || id >= size)
|
|
||||||
throw UnknownSymbolIDException(id);
|
|
||||||
else
|
|
||||||
return partition_value_map.find(id) != partition_value_map.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline string
|
|
||||||
SymbolTable::getPartition(int id) const throw (UnknownSymbolIDException)
|
|
||||||
{
|
|
||||||
if (id < 0 || id >= size || !hasPartition(id))
|
|
||||||
throw UnknownSymbolIDException(id);
|
|
||||||
else
|
|
||||||
return *(partition_value_map.at(id).first);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline string
|
|
||||||
SymbolTable::getPartitionValue(int id) const throw (UnknownSymbolIDException)
|
|
||||||
{
|
|
||||||
if (id < 0 || id >= size || !hasPartition(id))
|
|
||||||
throw UnknownSymbolIDException(id);
|
|
||||||
else
|
|
||||||
return *(partition_value_map.at(id).second);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SymbolType
|
inline SymbolType
|
||||||
SymbolTable::getType(int id) const throw (UnknownSymbolIDException)
|
SymbolTable::getType(int id) const throw (UnknownSymbolIDException)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue