Skip to content

Commit

Permalink
rename id util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrause committed Sep 4, 2024
1 parent e87a549 commit f1dfe5e
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 60 deletions.
8 changes: 4 additions & 4 deletions src/cmd/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void Benchmark::program(size_t id, size_t num_terms) {
auto program = parser.parse(seq.getProgramPath());
auto speed_reg = programEval(program, false, num_terms);
auto speed_inc = programEval(program, true, num_terms);
std::cout << "| " << seq.id_str() << " | "
std::cout << "| " << seq.idStr() << " | "
<< fillString(std::to_string(num_terms), 6) << " | "
<< fillString(speed_reg, 8) << " | " << fillString(speed_inc, 8)
<< " |" << std::endl;
Expand Down Expand Up @@ -158,7 +158,7 @@ void Benchmark::findSlow(int64_t num_terms, Operation::Type type) {
try {
program = parser.parse(in);
} catch (std::exception& e) {
Log::get().warn("Skipping " + oeisSeq.id_str() + ": " + e.what());
Log::get().warn("Skipping " + oeisSeq.idStr() + ": " + e.what());
continue;
}
if (type != Operation::Type::NOP && !ProgramUtil::hasOp(program, type)) {
Expand All @@ -169,7 +169,7 @@ void Benchmark::findSlow(int64_t num_terms, Operation::Type type) {
auto end_time = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
end_time - start_time);
Log::get().info(oeisSeq.id_str() + ": " + std::to_string(duration.count()) +
Log::get().info(oeisSeq.idStr() + ": " + std::to_string(duration.count()) +
"µs");
queue.push(std::pair<int64_t, int64_t>(duration.count(), oeisSeq.id));
}
Expand All @@ -178,7 +178,7 @@ void Benchmark::findSlow(int64_t num_terms, Operation::Type type) {
auto entry = queue.top();
queue.pop();
OeisSequence oeisSeq(entry.second);
std::cout << "[" << oeisSeq.id_str()
std::cout << "[" << oeisSeq.idStr()
<< "](https://loda-lang.org/edit/?oeis=" << entry.second
<< "): " << (entry.first / 1000) << "ms" << std::endl;
}
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void Commands::replace(const std::string& search_path,
ProgramUtil::removeOps(p, Operation::Type::NOP);
if (Subprogram::replaceAllExact(p, search, replace)) {
manager.updateProgram(id, p, ValidationMode::BASIC);
Log::get().info("Replaced in " + OeisSequence(id).id_str());
Log::get().info("Replaced in " + OeisSequence(id).idStr());
count++;
}
if (log_scheduler.isTargetReached()) {
Expand Down Expand Up @@ -345,8 +345,8 @@ void Commands::autoFold() {
}
}
if (folded) {
Log::get().info("Folded " + OeisSequence(main_id).id_str() + " using " +
OeisSequence(sub_id).id_str());
Log::get().info("Folded " + OeisSequence(main_id).idStr() + " using " +
OeisSequence(sub_id).idStr());
}
}
}
Expand Down Expand Up @@ -443,7 +443,7 @@ void Commands::testAnalyzer() {
continue;
}
OeisSequence seq(id);
auto id_str = seq.id_str();
auto id_str = seq.idStr();
std::ifstream in(seq.getProgramPath());
if (!in) {
continue;
Expand Down Expand Up @@ -525,7 +525,7 @@ void Commands::testPari(const std::string& test_id) {
}
if (!hasEvalError) {
Log::get().error(
"Expected evaluation error for " + seq.id_str() + ": " + e.what(),
"Expected evaluation error for " + seq.idStr() + ": " + e.what(),
true);
}
}
Expand Down Expand Up @@ -558,18 +558,18 @@ void Commands::testPari(const std::string& test_id) {
}
}
Log::get().info("Checking " + std::to_string(numTerms) + " terms of " +
seq.id_str() + ": " + pari_formula.toString());
seq.idStr() + ": " + pari_formula.toString());

if (numTerms == 0) {
Log::get().warn("Skipping " + seq.id_str());
Log::get().warn("Skipping " + seq.idStr());
continue;
}

// evaluate LODA program
try {
evaluator.eval(program, expSeq, numTerms);
} catch (const std::exception&) {
Log::get().warn("Cannot evaluate " + seq.id_str());
Log::get().warn("Cannot evaluate " + seq.idStr());
continue;
}
if (expSeq.empty()) {
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ bool Test::checkIncEval(const Settings& settings, size_t id, std::string path,
auto name = path;
if (path.empty()) {
OeisSequence s(id);
name = s.id_str();
name = s.idStr();
path = s.getProgramPath();
}
Parser parser;
Expand Down Expand Up @@ -881,7 +881,7 @@ void checkSeqAgainstTestBFile(int64_t seq_id, int64_t offset,
std::stringstream buf;
t.getTerms(max_num_terms).to_b_file(buf, offset);
std::ifstream bfile(std::string("tests") + FILE_SEP + "sequence" + FILE_SEP +
t.id_str("b") + ".txt");
t.idStr("b") + ".txt");
std::string x, y;
while (std::getline(bfile, x)) {
if (!std::getline(buf, y)) {
Expand Down Expand Up @@ -1068,7 +1068,7 @@ void Test::checkFormulas(const std::string& testFile, FormulaType type) {
FormulaGenerator generator;
for (const auto& e : map) {
OeisSequence seq(e.first);
Log::get().info("Testing formula for " + seq.id_str() + ": " + e.second);
Log::get().info("Testing formula for " + seq.idStr() + ": " + e.second);
auto p = parser.parse(seq.getProgramPath());
Formula f;
if (!generator.generate(p, seq.id, f, true)) {
Expand Down Expand Up @@ -1371,8 +1371,8 @@ void eval(const Program& p, Evaluator& evaluator, Sequence& s) {

void Test::testMatcherPair(Matcher& matcher, size_t id1, size_t id2) {
Log::get().info("Testing " + matcher.getName() + " matcher for " +
OeisSequence(id1).id_str() + " -> " +
OeisSequence(id2).id_str());
OeisSequence(id1).idStr() + " -> " +
OeisSequence(id2).idStr());
Parser parser;
Evaluator evaluator(settings);
auto p1 = parser.parse(OeisSequence(id1).getProgramPath());
Expand All @@ -1399,7 +1399,7 @@ void Test::testMatcherPair(Matcher& matcher, size_t id1, size_t id2) {
ProgramUtil::print(result[0].second, std::cout);
Log::get().error(matcher.getName() +
" matcher generated wrong program for " +
OeisSequence(id2).id_str(),
OeisSequence(id2).idStr(),
true);
}
}
3 changes: 1 addition & 2 deletions src/eval/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@ std::pair<Number, size_t> Interpreter::callSeq(int64_t id, const Number& arg) {

// check for recursive calls
if (running_programs.find(id) != running_programs.end()) {
throw std::runtime_error("Recursion detected: " +
OeisSequence(id).id_str());
throw std::runtime_error("Recursion detected: " + OeisSequence(id).idStr());
}

// evaluate program
Expand Down
8 changes: 4 additions & 4 deletions src/form/formula_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool FormulaGenerator::update(const Operation& op) {
case Operation::Type::SEQ: {
res =
Expression(Expression::Type::FUNCTION,
OeisSequence(source.value.asInt()).id_str(), {prevTarget});
OeisSequence(source.value.asInt()).idStr(), {prevTarget});
break;
}
case Operation::Type::TRN: {
Expand Down Expand Up @@ -443,7 +443,7 @@ bool addProgramIds(const Program& p, std::set<int64_t>& ids) {
bool FormulaGenerator::generate(const Program& p, int64_t id, Formula& result,
bool withDeps) {
if (id > 0) {
Log::get().debug("Generating formula for " + OeisSequence(id).id_str());
Log::get().debug("Generating formula for " + OeisSequence(id).idStr());
}
formula.clear();
freeNameIndex = 0;
Expand All @@ -461,7 +461,7 @@ bool FormulaGenerator::generate(const Program& p, int64_t id, Formula& result,
Parser parser;
for (auto id2 : ids) {
OeisSequence seq(id2);
Log::get().debug("Adding dependency " + seq.id_str());
Log::get().debug("Adding dependency " + seq.idStr());
Program p2;
try {
p2 = parser.parse(seq.getProgramPath());
Expand All @@ -474,7 +474,7 @@ bool FormulaGenerator::generate(const Program& p, int64_t id, Formula& result,
return false;
}
auto from = getCellName(Program::INPUT_CELL);
auto to = seq.id_str();
auto to = seq.idStr();
Log::get().debug("Replacing " + from + " by " + to);
formula.replaceName(from, to);
result.entries.insert(formula.entries.begin(), formula.entries.end());
Expand Down
8 changes: 4 additions & 4 deletions src/mine/finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ std::pair<std::string, Program> Finder::checkProgramExtended(
if (check_minimized.first == status_t::ERROR) {
if (check_vanilla.first == status_t::OK) {
// looks like the minimization changed the semantics of the program
notifyUnfoldOrMinimizeProblem(result.second, seq.id_str());
notifyUnfoldOrMinimizeProblem(result.second, seq.idStr());
}
// we ignore the case where the base program has a warning and minimized
// program an error, because it indicates a problem in the base program
Expand Down Expand Up @@ -215,7 +215,7 @@ std::pair<std::string, Program> Finder::checkProgramBasic(
if (!is_new) {
// check if another miner already submitted a program for this sequence
if (change_type == first) {
Log::get().debug("Skipping update of " + seq.id_str() +
Log::get().debug("Skipping update of " + seq.idStr() +
" because program is not new");
return result;
}
Expand All @@ -228,7 +228,7 @@ std::pair<std::string, Program> Finder::checkProgramBasic(
}
// compare with hash of existing program
if (previous_hash != OeisProgram::getTransitiveProgramHash(existing)) {
Log::get().debug("Skipping update of " + seq.id_str() +
Log::get().debug("Skipping update of " + seq.idStr() +
" because of hash mismatch");
return result;
}
Expand Down Expand Up @@ -370,7 +370,7 @@ std::string Finder::isOptimizedBetter(Program existing, Program optimized,
auto num_check = OeisProgram::getNumCheckTerms(full_check);
auto terms = seq.getTerms(num_check);
if (terms.empty()) {
Log::get().error("Error fetching b-file for " + seq.id_str(), true);
Log::get().error("Error fetching b-file for " + seq.idStr(), true);
}

// evaluate optimized program for fixed number of terms
Expand Down
2 changes: 1 addition & 1 deletion src/mine/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void Miner::submit(const std::string &path, std::string id) {
OeisSequence seq(id);
Settings settings(this->settings);
settings.print_as_b_file = false;
Log::get().info("Validating program for " + seq.id_str());
Log::get().info("Validating program for " + seq.idStr());
Evaluator evaluator(settings);
auto terms = seq.getTerms(OeisSequence::FULL_SEQ_LENGTH);
auto num_required = OeisProgram::getNumRequiredTerms(program);
Expand Down
8 changes: 4 additions & 4 deletions src/mine/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ void Stats::save(std::string path) {
std::ofstream cal(path + "call_graph.csv");
cal << CALL_GRAPH_HEADER << "\n";
for (auto it : call_graph) {
cal << OeisSequence(it.first).id_str() << sep
<< OeisSequence(it.second).id_str() << "\n";
cal << OeisSequence(it.first).idStr() << sep
<< OeisSequence(it.second).idStr() << "\n";
}
cal.close();

Expand Down Expand Up @@ -419,13 +419,13 @@ int64_t Stats::getTransitiveLength(size_t id) const {
visited_programs.clear();
if (printed_recursion_warning.find(id) == printed_recursion_warning.end()) {
printed_recursion_warning.insert(id);
Log::get().warn("Recursion detected: " + OeisSequence(id).id_str());
Log::get().warn("Recursion detected: " + OeisSequence(id).idStr());
}
return -1;
}
visited_programs.insert(id);
if (id >= program_lengths.size()) {
Log::get().warn("Invalid reference: " + OeisSequence(id).id_str());
Log::get().warn("Invalid reference: " + OeisSequence(id).idStr());
return -1;
}
int64_t length = program_lengths.at(id);
Expand Down
2 changes: 1 addition & 1 deletion src/oeis/oeis_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void OeisList::mergeMap(const std::string& file_name,
}
std::ofstream out(getListsHome() + file_name);
for (auto it : map) {
out << OeisSequence(it.first).id_str() << ": " << it.second
out << OeisSequence(it.first).idStr() << ": " << it.second
<< std::endl; // flush at every line to avoid corrupt data
}
out.close();
Expand Down
14 changes: 7 additions & 7 deletions src/oeis/oeis_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,12 @@ void OeisManager::generateLists() {
replaceAll(buf, "_", "\\_");
replaceAll(buf, "|", "\\|");
list_files.at(list_index)
<< "* [" << s.id_str() << "](https://oeis.org/" << s.id_str()
<< "* [" << s.idStr() << "](https://oeis.org/" << s.idStr()
<< ") ([program](/edit/?oeis=" << s.id << ")): " << buf << "\n";

num_processed++;
} else {
no_loda << s.id_str() << ": " << s.name << "\n";
no_loda << s.idStr() << ": " << s.name << "\n";
}
}

Expand All @@ -531,8 +531,8 @@ void OeisManager::generateLists() {
std::ofstream list_file(list_path);
list_file << "---\n";
list_file << "layout: page\n";
list_file << "title: Programs for " << start.id_str() << "-"
<< end.id_str() << "\n";
list_file << "title: Programs for " << start.idStr() << "-" << end.idStr()
<< "\n";
list_file << "permalink: /list" << i << "/\n";
list_file << "---\n";
list_file << "List of integer sequences with links to LODA programs."
Expand Down Expand Up @@ -723,8 +723,8 @@ void OeisManager::alert(Program p, size_t id, const std::string &prefix,
full += ". " + sub;
}
Log::AlertDetails details;
details.title = seq.id_str();
details.title_link = seq.url_str();
details.title = seq.idStr();
details.title_link = seq.urlStr();
details.color = color;
std::stringstream buf;
// TODO: code block markers must be escaped for Slack, but not for Discord
Expand Down Expand Up @@ -951,7 +951,7 @@ std::vector<Program> OeisManager::loadAllPrograms() {
programs[id] = parser.parse(in);
loaded++;
} catch (const std::exception &e) {
Log::get().warn("Skipping " + seq.id_str() + ": " + e.what());
Log::get().warn("Skipping " + seq.idStr() + ": " + e.what());
continue;
}
if (scheduler.isTargetReached() || loaded == num_programs) {
Expand Down
4 changes: 2 additions & 2 deletions src/oeis/oeis_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ std::vector<bool> OeisProgram::collectLatestProgramIds(
OeisSequence seq(id_str);
if (isFile(seq.getProgramPath())) {
if (status == "A" && num_added_ids < max_added_programs) {
Log::get().debug("Added program for " + seq.id_str());
Log::get().debug("Added program for " + seq.idStr());
ids.insert(seq.id);
num_added_ids++;
} else if (status == "M" &&
num_modified_ids < max_modified_programs) {
Log::get().debug("Modified program for " + seq.id_str());
Log::get().debug("Modified program for " + seq.idStr());
ids.insert(seq.id);
num_modified_ids++;
}
Expand Down
Loading

0 comments on commit f1dfe5e

Please sign in to comment.