From 67456f9f7af754750faeea6f1e66b14b910d8751 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Mon, 18 Jun 2012 20:28:42 -0400 Subject: add non-const iterators to sparse vector, speed up model1 code --- training/ttables.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'training/ttables.h') diff --git a/training/ttables.h b/training/ttables.h index bf3351d2..9baa13ca 100644 --- a/training/ttables.h +++ b/training/ttables.h @@ -4,6 +4,7 @@ #include #include +#include "sparse_vector.h" #include "m.h" #include "wordid.h" #include "tdict.h" @@ -68,18 +69,18 @@ class TTable { } return *this; } - void ShowTTable() { - for (Word2Word2Double::iterator it = ttable.begin(); it != ttable.end(); ++it) { - Word2Double& cpd = it->second; - for (Word2Double::iterator j = cpd.begin(); j != cpd.end(); ++j) { + void ShowTTable() const { + for (Word2Word2Double::const_iterator it = ttable.begin(); it != ttable.end(); ++it) { + const Word2Double& cpd = it->second; + for (Word2Double::const_iterator j = cpd.begin(); j != cpd.end(); ++j) { std::cerr << "P(" << TD::Convert(j->first) << '|' << TD::Convert(it->first) << ") = " << j->second << std::endl; } } } - void ShowCounts() { - for (Word2Word2Double::iterator it = counts.begin(); it != counts.end(); ++it) { - Word2Double& cpd = it->second; - for (Word2Double::iterator j = cpd.begin(); j != cpd.end(); ++j) { + void ShowCounts() const { + for (Word2Word2Double::const_iterator it = counts.begin(); it != counts.end(); ++it) { + const Word2Double& cpd = it->second; + for (Word2Double::const_iterator j = cpd.begin(); j != cpd.end(); ++j) { std::cerr << "c(" << TD::Convert(j->first) << '|' << TD::Convert(it->first) << ") = " << j->second << std::endl; } } -- cgit v1.2.3