test: capture scroll generate() golden output (pre-migration)
This commit is contained in:
48
scripts/build_golden_scroll.py
Normal file
48
scripts/build_golden_scroll.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Capture golden scroll event sequences from current torch implementation."""
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Allow running as `uv run python scripts/build_golden_scroll.py` from project root.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
from ai_mouse import generate_scroll
|
||||
|
||||
CASES: list[tuple[int, int, str]] = [
|
||||
(0, 1500, "target"),
|
||||
(0, 500, "precise"),
|
||||
(0, 5000, "fast"),
|
||||
(2000, 0, "target"), # upward
|
||||
(0, 800, "precise"),
|
||||
(0, 3500, "fast"),
|
||||
(1000, 1200, "precise"), # tiny scroll
|
||||
(0, 10000, "fast"), # very long
|
||||
]
|
||||
SEEDS = (0, 1, 2, 3)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
out: dict[str, np.ndarray] = {}
|
||||
for case_idx, (start_y, end_y, mode) in enumerate(CASES):
|
||||
for seed in SEEDS:
|
||||
random.seed(seed)
|
||||
np.random.seed(seed)
|
||||
torch.manual_seed(seed)
|
||||
events = generate_scroll(start_y, end_y, mode=mode)
|
||||
arr = np.array(
|
||||
[[e["deltaY"], e["deltaMode"], e["t"]] for e in events],
|
||||
dtype=np.int64,
|
||||
)
|
||||
out[f"case{case_idx}_seed{seed}"] = arr
|
||||
out_path = Path("tests/unit/data/golden_scroll.npz")
|
||||
np.savez_compressed(out_path, **out)
|
||||
print(f"Wrote {len(out)} scroll golden traces to {out_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user