Skip to content

Add Rust-powered Learner1D with PyO3 bindings#2

Open
basnijholt wants to merge 4 commits intomainfrom
issue-096-impl
Open

Add Rust-powered Learner1D with PyO3 bindings#2
basnijholt wants to merge 4 commits intomainfrom
issue-096-impl

Conversation

@basnijholt
Copy link
Copy Markdown
Member

Native Rust Learner1D module: BTreeMap-based, 12-15× faster than Python adaptive.Learner1D for typical workloads. 6 built-in losses + Python callback fallback. run() method keeps the adaptive loop in Rust (only user f(x) crosses PyO3). 56 Python tests + 4 Rust tests pass. ~1,840 LOC total. 3 commits: feat, fix (review findings), refactor (cleanup pass −281 lines).

Implement a 1D adaptive sampling learner backed by BTreeMap/BTreeSet
internals, matching the semantics of Python's adaptive.Learner1D.

- Core Learner1D with tell/tell_pending/tell_many/ask/run methods
- LossManager priority queue with O(1) interval lookup + sorted access
- Built-in loss functions: Default, Uniform, Resolution, Curvature,
  Triangle, AbsMinLog, and Python callback support
- 44 comprehensive Python tests covering all functionality
- Python benchmark script for performance measurement
- Replace .expect() with error handling in python_callback_loss (CRITICAL)
- Store out-of-bounds data separately to prevent neighbor query pollution (HIGH)
- Keep x_scale constant as bounds span, not derived from data (HIGH)
- Expose loss(real) parameter in PyO3 binding (MEDIUM)
- Fix empty learner linspace to include right endpoint (MEDIUM)
- Add interval-based tiebreaking in ask() loss comparison (MEDIUM)
- Use iterator .any() for has_missing_bounds instead of Vec allocation (LOW)
- Avoid cloning in rebuild_scale via free function (LOW)
- Add 12 new tests covering OOB tells, callback exceptions, loss(real=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant