| 46 | } // namespace |
| 47 | |
| 48 | int main() { |
| 49 | std::mt19937_64 rng(12345); |
| 50 | std::uniform_real_distribution<double> u(0.0, 1.0); |
| 51 | const fnx::RowCost c; |
| 52 | int fails = 0, cases = 0; |
| 53 | for (int it = 0; it < 4000; ++it) { |
| 54 | const int n = 1 + (int) (rng() % 6); |
| 55 | std::vector<fnx::RowOffer> L((size_t) n); |
| 56 | for (auto& o : L) { |
| 57 | o.chain = rng() % 2; |
| 58 | o.avail = (int) (rng() % (o.chain ? 7 : 16)); |
| 59 | const double p = u(rng); // per-position acceptance, non-increasing reach |
| 60 | double r = 1.0; |
| 61 | for (int j = 0; j < o.avail; ++j) o.reach.push_back(r *= p * (0.8 + 0.2 * u(rng))); |
| 62 | } |
| 63 | const double base = c.round_ms + c.rows_ms(n) + c.call_ms * n; |
| 64 | const std::vector<int> d = fnx::plan_rows(L, ROWS, base, c); |
| 65 | int rows = n; |
| 66 | for (int i = 0; i < n; ++i) { |
| 67 | rows += d[(size_t) i]; |
| 68 | if (d[(size_t) i] < 0 || d[(size_t) i] > L[(size_t) i].avail) { |
| 69 | std::printf("case %d: lane %d gets %d drafts of %d offered\n", it, i, d[(size_t) i], L[(size_t) i].avail); |
| 70 | ++fails; |
| 71 | } |
| 72 | } |
| 73 | if (rows > ROWS) { |
| 74 | std::printf("case %d: %d rows\n", it, rows); |
| 75 | ++fails; |
| 76 | } |
| 77 | const double got = rate(L, d, base, c), best = best_rate(L, base, c); |
| 78 | if (got < best * (1.0 - 1e-9)) { |
| 79 | std::printf("case %d (%d lanes): %.6f tokens/ms, the best split %.6f\n", it, n, got, best); |
| 80 | ++fails; |
| 81 | } |
| 82 | ++cases; |
| 83 | } |
| 84 | // one lane, a chain: chain_len's choice (k drafts, at least 1) where the first draft pays at all |
| 85 | for (int it = 0; it < 2000; ++it) { |
| 86 | fnx::RowOffer o; |
| 87 | o.chain = true; |
| 88 | o.avail = 1 + (int) (rng() % 6); |
| 89 | double r = 1.0; |
| 90 | const double p = 0.2 + 0.8 * u(rng); |
| 91 | for (int j = 0; j < o.avail; ++j) o.reach.push_back(r *= p * (0.8 + 0.2 * u(rng))); |
| 92 | int best = 1; |
| 93 | double best_rate = -1.0, expect = 1.0; |
| 94 | for (int k = 1; k <= o.avail; ++k) { |
| 95 | expect += o.reach[(size_t) k - 1]; |
| 96 | const double rt = expect / (c.round_ms + c.rows_ms(k + 1) + std::max(0, k - 1) * c.chain_ms); |
| 97 | if (rt > best_rate) best_rate = rt, best = k; |
| 98 | } |
| 99 | const int d = fnx::plan_rows({o}, ROWS, c.round_ms, c)[0]; |
| 100 | if (d != best) { |
| 101 | std::printf("one lane: plan %d drafts, chain_len %d (avail %d, reach0 %.3f)\n", d, best, o.avail, o.reach[0]); |
| 102 | ++fails; |
| 103 | } |
| 104 | ++cases; |
| 105 | } |
nothing calls this directly
no test coverage detected