From 78a216344f69e260425f39b701ceadd42a2c6ed9 Mon Sep 17 00:00:00 2001 From: sebastien Date: Mon, 14 Sep 2009 16:50:24 +0000 Subject: [PATCH] dynare++ tensor library: improve on implementation of TensorContainer::writeMMap() git-svn-id: https://www.dynare.org/svn/dynare/trunk@2923 ac1d8469-bf42-47a9-8791-bf33cf982152 --- dynare++/tl/cc/t_container.hweb | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/dynare++/tl/cc/t_container.hweb b/dynare++/tl/cc/t_container.hweb index ed4334f7b..be411b7f9 100644 --- a/dynare++/tl/cc/t_container.hweb +++ b/dynare++/tl/cc/t_container.hweb @@ -60,6 +60,7 @@ is multiplied by unfolded tensors $g$ yielding unfolded tensor $B$. #include #include +#include @<|ltsym| predicate@>; @<|TensorContainer| class definition@>; @@ -295,23 +296,19 @@ void writeMat4(FILE* fd, const char* prefix) const @ Output to the Memory Map. @<|TensorContainer::writeMMap| code@>= -void writeMMap(map* mm) const +void writeMMap(map &mm, const string &prefix) const { - for (const_iterator it = begin(); it != end(); ++it) { - char lname[100]; - sprintf(lname, "g"); - const Symmetry& sym = (*it).first; - for (int i = 0; i < sym.num(); i++) { - char tmp[10]; - sprintf(tmp, "_%d", sym[i]); - strcat(lname, tmp); - } - ConstTwoDMatrix mx(*((*it).second)); - mm->insert(make_pair(string(lname),mx)); - } + ostringstream lname; + for (const_iterator it = begin(); it != end(); ++it) { + lname.str(prefix); + lname << "_g"; + const Symmetry& sym = (*it).first; + for (int i = 0; i < sym.num(); i++) + lname << "_" << sym[i]; + mm.insert(make_pair(lname.str(), ConstTwoDMatrix(*((*it).second)))); + } } - @ Here we fetch all tensors given by symmetry and equivalence. We go through all equivalence classes, calculate implied symmetry, and fetch its tensor storing it in the same order to the vector.