Skip to content

Commit 4fc9095

Browse files
committed
fix validation
1 parent 6dbc6cf commit 4fc9095

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ To install or update LODA, please follow the [installation instructions](https:/
22

33
## [Unreleased]
44

5+
## v22.12.9
6+
7+
### Bugfixes
8+
9+
* Fix decision making for better/faster programs
10+
511
## v22.12.8
612

713
### Enhancements

src/finder.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ size_t getBadOpsCount(const Program &p) {
259259
return num_ops;
260260
}
261261

262+
bool isBetterIndirectMemory(const Program &existing, const Program &optimized) {
263+
return (ProgramUtil::hasIndirectOperand(existing) &&
264+
!ProgramUtil::hasIndirectOperand(optimized) &&
265+
!ProgramUtil::hasOp(optimized, Operation::Type::SEQ));
266+
}
267+
262268
std::string Finder::isOptimizedBetter(Program existing, Program optimized,
263269
const OeisSequence &seq) {
264270
static const std::string not_better;
@@ -318,6 +324,11 @@ std::string Finder::isOptimizedBetter(Program existing, Program optimized,
318324
} else if (optimized_bad_count > existing_bad_count) {
319325
return not_better; // worse
320326
}
327+
if (isBetterIndirectMemory(existing, optimized)) {
328+
return "Simpler";
329+
} else if (isBetterIndirectMemory(optimized, existing)) {
330+
return not_better; // worse
331+
}
321332

322333
// ======= EVALUATION CHECKS =========
323334

@@ -353,22 +364,20 @@ std::string Finder::isOptimizedBetter(Program existing, Program optimized,
353364
const auto existing_steps = evaluator.eval(existing, tmp, num_terms, false);
354365

355366
// compare number of successfully computed terms
356-
int64_t existing_terms = static_cast<int64_t>(
357-
static_cast<double>(existing_steps.runs) * THRESHOLD_BETTER);
358-
int64_t optimized_terms = optimized_steps.runs;
359-
if (optimized_terms > existing_terms) {
367+
double existing_terms = existing_steps.runs;
368+
double optimized_terms = optimized_steps.runs;
369+
if (optimized_terms > (existing_terms * THRESHOLD_BETTER)) {
360370
return "Better";
361-
} else if (optimized_terms < existing_terms) {
371+
} else if (existing_terms > (optimized_terms * THRESHOLD_BETTER)) {
362372
return not_better; // worse
363373
}
364374

365375
// compare number of execution cycles
366-
int64_t existing_total = existing_steps.total;
367-
int64_t optimized_total = static_cast<int64_t>(
368-
static_cast<double>(optimized_steps.total) * THRESHOLD_FASTER);
369-
if (optimized_total < existing_total) {
376+
double existing_total = existing_steps.total;
377+
double optimized_total = optimized_steps.total;
378+
if (existing_total > (optimized_total * THRESHOLD_FASTER)) {
370379
return "Faster";
371-
} else if (optimized_total > existing_total) {
380+
} else if (optimized_total > (existing_total * THRESHOLD_FASTER)) {
372381
return not_better; // worse
373382
}
374383

src/include/finder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class Finder {
5050
const OeisSequence &seq);
5151

5252
private:
53-
static constexpr double THRESHOLD_BETTER = 1.05;
54-
static constexpr double THRESHOLD_FASTER = 1.05;
53+
static constexpr double THRESHOLD_BETTER = 1.1;
54+
static constexpr double THRESHOLD_FASTER = 1.1;
5555

5656
void findAll(const Program &p, const Sequence &norm_seq,
5757
const std::vector<OeisSequence> &sequences,

0 commit comments

Comments
 (0)