bool transform2Inplace(IMutableHypergraph<Arc>& l, IHypergraph<Arc> const& r) { SDL_DEBUG(Hypergraph.HgConcat, "Concat input 1:\n" << l); SDL_DEBUG(Hypergraph.HgConcat, "Concat input 2:\n" << r); hgConcat(&l, r, opt); SDL_DEBUG(Hypergraph.HgConcat, "Result:\n" << l); return true; }
void add(std::string const& line, std::set<Sym>* allLabels, IVocabularyPtr& pVoc, bool testMode) { std::stringstream ss(line); std::string word, pos, label; ss >> word >> pos >> label; if (word.empty() || pos.empty() || label.empty()) { SDL_THROW_LOG(CrfDemo, InvalidInputException, "Bad line: " << line); } words.push_back(pVoc->add(word, kTerminal)); poss.push_back(pVoc->add(pos, kTerminal)); labels.push_back(pVoc->add(label, kTerminal)); SDL_DEBUG(CrfDemo, "id(" << word << "): " << words.back()); SDL_DEBUG(CrfDemo, "id(" << pos << "): " << poss.back()); SDL_DEBUG(CrfDemo, "id(" << label << "): " << labels.back()); if (!testMode) { allLabels->insert(labels.back()); } }
void start() { if (enable) { expect = size(); if (log) SDL_DEBUG(Leak.LeakCheck.start, "initial count of "<<*this << ": " << expect); } }
ToArc* operator()(FromArc const* arc) const { // Token spans from first tail to head: StateIdContainer const& tails = arc->tails(); assert(!tails.empty()); TokenWeight w(Token::createEmptyToken(tails[0], arc->head()), arc->weight()); ToArc* toArc = new ToArc(arc->head(), tails, w); SDL_DEBUG(Hypergraph.SetTokenWeightMapper, "Created " << *toArc); return toArc; }
void toHypergraph(std::string const& line, IMutableHypergraph<A>* phg, std::size_t lineNum = 0) const { Strings words = parseTokens(line, (ParseTokensOptions const&)*this); SDL_DEBUG(Hypergraph.HgConvertString, lineNum << ": " << printer(words, Util::RangeSep(" ", "", ""))); SDL_INFO(Hypergraph.HgConvertString, lineNum << ": len=" << words.size()); phg->clear(properties()); assert(phg->storesArcs()); assert(phg->getVocabulary()); stringToHypergraph(words, phg); }
std::size_t MemoryInfo::size() { // unsigned long long memoryUsage; std::string line; SDL_DEBUG(Util.MemoryInfo, "reading " << memoryFilename); std::ifstream memoryFileStream(memoryFilename); if (!memoryFileStream) SDL_THROW_LOG(Util.MemoryInfo, FileException, "couldn't open process stat file '" << memoryFilename << "' for memory usage"); std::getline(memoryFileStream, line); const std::string val0 = getColumn(line, 22); // virtual memory size column if (val0.empty()) { // TODO@MD: Fix for non-linux systems return 0; } std::size_t val = sdl::lexical_cast<std::size_t>(val0); return val; }
void finish() { if (enable) { std::size_t got = size(); if (log) SDL_DEBUG(Leak.LeakCheck.finish, "final count of " << *this << ": " << got << " (initial=" << expect << ")"); if (got > expect) { /// since we reset cache every N segs, the last one might clear more than it increased if (log) { // For Production builds, log this error without throwing an exception SDL_THROW_IF(!SDL_SUPPRESS_IGNORABLE_WARNINGS, Leak.ObjectCount, ProgrammerMistakeException, "expected remaining count of " << *this << " to be its initial value " << expect << " but got " << got << " instead (make sure multiple threads aren't confusing your check boundaries)"); } else if (got) { std::cerr << "\nWARNING: LeakCheck<" << *this << ">: " << got << " live objects at exit instead of the expected " << expect << '\n'; } } } enable = false; }