Repository navigation
refactor(phs): one log_reference keyword for the log transform - #209
Conversation
Replace the exported `ConstantRef` / `PHSLogTransform` and the keywords `reference_interp` / `reference_data` with one keyword, `log_reference`: `nothing`, a nonzero constant (used as given), or a callable ρ₀(q) that is called as before, `ρ₀(q)` and `ρ₀(q; deriv = ops)`. - Validate the reference at build, at grid precision: every data/ρ₀ must be positive and finite, and the error names the node; Bool and arrays are rejected. - Drop `reference_data`: its only use, a PHS of ρ₀ on the data grid, gives the constant-reference result. - One-shot methods forward their keywords to the persistent constructor; the one-shot blend_factor default stays 2.0. - Move the log-reference code into src/phs/phs_log_reference.jl. - Docs: fix the log-transform derivative formulas and the NaN example. - Tests: new test_phs_log_reference.jl; pins F4, F5, F7 and R11 pass, F6 is added as broken.
FastInterpolations.jl BenchmarksAll benchmarks (71 total, click to expand)
|
| Benchmark | Current | Previous | Imm. Ratio | Grad. Ratio | Tier |
|---|---|---|---|---|---|
13_nd_oneshot_gridquery/bilinear_2d_sort_rand |
10057.1 ns |
8824.3 ns |
1.14 |
1.079 |
immediate |
7_cubic_vec/scalar_query |
9.71 ns |
8.5 ns |
1.141 |
0.882 |
immediate |
Thresholds: immediate > 1.1x (vs latest master), gradual > 1.1x (vs sliding window)
Runner:
znver3|4c— AMD EPYC 7763 64-Core Processor, julia 1.13.1. Times are min-merged and compared only against this same machine's history.
This comment was automatically generated by Benchmark workflow.
A single warm-up only runs the stencil-coefficient cache-miss path. On Julia LTS the first cache-hit run then compiles inside @allocated (~192 KB) when the worker is fresh, as under the parallel runner. The same happens on master; this is a test warm-up gap, not a regression.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The API migration is consistent across implementation, tests, documentation, and examples, with no unresolved correctness issues found.
Review effort: Balanced
Findings: None
What changed in this PR
Refactors the PHS log transform into a single validated log_reference API.
Changes:
- Replaces legacy reference types and keywords with
log_reference. - Adds validation, constant/callable reference handling, and derivative support.
- Updates tests, documentation, and example scripts.
| File | Description |
|---|---|
src/FastInterpolations.jl |
Removes legacy exports. |
src/phs/phs.jl |
Loads reference implementation. |
src/phs/phs_types.jl |
Removes public reference types. |
src/phs/phs_log_reference.jl |
Implements reference resolution and validation. |
src/phs/phs_interpolant.jl |
Adds the new constructor keyword. |
src/phs/phs_eval.jl |
Evaluates constant and callable references. |
src/phs/phs_oneshot.jl |
Forwards constructor keywords. |
test/test_phs_nd.jl |
Migrates existing tests. |
test/test_phs_log_reference.jl |
Adds comprehensive reference tests. |
test/test_phs_broken_pins.jl |
Updates and promotes regression pins. |
docs/src/interpolation/phs.md |
Documents behavior and formulas. |
docs/src/api/phs.md |
Updates API reference. |
scripts/phs/phs_density_comparison.jl |
Migrates comparison script. |
scripts/phs/phs_density_comparison_simplified.jl |
Migrates simplified script. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@twilsonco One keyword, As far as I can tell, every case the old API covered can still be expressed. If something in your use case no longer works or is harder to write now, please let me know here. Performance and the other open items will come in the next follow-up PRs. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #209 +/- ##
=======================================
Coverage 96.28% 96.29%
=======================================
Files 171 172 +1
Lines 15467 15484 +17
=======================================
+ Hits 14893 14910 +17
Misses 574 574
🚀 New features to boost your workflow:
|
|
Thanks @mgyoo86. I'll review how I'm using it and update here to confirm all looks good. |
|
Hi @twilsonco, I merged this PR to prepare for a new release, as several other fixes and performance improvements are already lined up. I think the new API should be fine, but please feel free to comment here or open an issue if you run into any problems. |
Follow-up to #136.
Summary
The PHS log-density transform (interpolate ln(ρ/ρ₀), return ρ₀·G) is now set with one keyword,
log_reference:nothing(default, off), a nonzero constant, or a callable ρ₀(q). The exportedConstantRefandPHSLogTransformand the keywordsreference_interp/reference_dataare removed. PHS is not in a release yet (merged after v0.4.19), so there is no deprecation path.The public PHS surface is now
phs_interp,phs_interp!andPHSInterpolantND.Behavior changes
Bool, arrays, and constants that vanish at grid precision (Float32grid with1e-100gave NaN). Master stored-Inf, threw a bareDomainError/MethodError, or returned NaN.reference_datais dropped: its use was the nested form above, where the reference is a PHS of ρ₀ on the data grid. That reference cancels itself in the local PHS operator, so the result equals the constant reference (differences ~1e-8 of the values, far below the interpolation error). A reference only adds accuracy with information the grid lacks: an analytic ρ₀, or an interpolant of finer data.Unchanged
ρ₀(q)for values,ρ₀(q; deriv = ops)for derivatives, and once per grid node at build. The ForwardDiff extension is untouched.blend_factordefault stays 2.0 (persistent: 1.0, §R7); it moves with the blend fixes.Tests
test_phs_log_reference.jl(12 testitems): constant-value invariance, negative data, invalid references, callables answeringderiv(declared or throughkw...), allocation pins.derivtuple with its value) pass. New pin §F6 (a clear error when a value-only reference gets a derivative query) stays broken, as do §R2, §R7, §R9 and §R10.