Skip to content

Comments

(breaking): new AbstractSide API replacing old Symbol-based API#41

Merged
mgyoo86 merged 6 commits intomasterfrom
feat/AbstractSide
Feb 23, 2026
Merged

(breaking): new AbstractSide API replacing old Symbol-based API#41
mgyoo86 merged 6 commits intomasterfrom
feat/AbstractSide

Conversation

@mgyoo86
Copy link
Collaborator

@mgyoo86 mgyoo86 commented Feb 20, 2026

Summary

Replace the Symbol-based side API (:nearest, :left, :right) in constant interpolation with a typed AbstractSide hierarchy (NearestSide(), LeftSide(), RightSide()). This mirrors the AbstractExtrap migration completed in the previous PR and eliminates the last Symbol-dispatched API surface in the package.

This is a breaking change for any code using side=:nearest, side=:left, or side=:right.

Deleted Code

Removed Lines Original Purpose
@_dispatch_side macro ~100 Symbol → Val branching at call sites
_validate_side(::Symbol) ~10 Runtime symbol validation
SideVal type alias ~5 Union{Val{:nearest}, Val{:left}, Val{:right}}
Manual side if-else in integrate_api.jl ~30 Manually unrolled branches to avoid union blowup
_to_side_val(::Symbol) ~15 Symbol → Val conversion helper

Net: 49 files changed, −199 lines (663 insertions, 862 deletions)

New Exports

export AbstractSide, NearestSide, LeftSide, RightSide

Migration Guide

# Before (removed)
itp = constant_interp(x, y; side=:nearest)
itp = constant_interp(x, y; side=:left)
itp = constant_interp(x, y; side=:right)

# After (required)
itp = constant_interp(x, y; side=NearestSide())
itp = constant_interp(x, y; side=LeftSide())
itp = constant_interp(x, y; side=RightSide())

# ND per-axis specification
itp = constant_interp_nd((x, y), data; side=(LeftSide(), RightSide()))

Impact

  • All constant interpolation (1D, ND, series, oneshot) now uses typed dispatch
  • PolyFit kernels (_compute_deriv1, _estimate_endpoint_derivative) use LeftSide/RightSide instead of Val{:left}/Val{:right}
  • Integration paths simplified — no manual side unrolling needed
  • Zero behavioral changes — all numerical outputs identical

…rchy

Replace :left/:right/:nearest Symbols and Val-based dispatch with proper
type hierarchy (AbstractSide → NearestSide, LeftSide, RightSide), mirroring
the recent AbstractExtrap refactoring.

Removed: SideVal alias, @_dispatch_side/@_dispatch_side_nd macros,
_validate_side, _is_uniform_side, _to_side_val/_to_side_vals helpers,
and 6 manual if-else dispatch blocks in integration code.

BREAKING CHANGE: side kwarg now requires AbstractSide instances instead
of Symbols (e.g. side=NearestSide() instead of side=:nearest).
…ide dispatch

Replace Val{:left}/Val{:right} Symbol-based dispatch with LeftSide/RightSide
type hierarchy across all polyfit kernel functions and their callers:

- _compute_deriv1: 14 specialized methods + generic fallback
- _compute_deriv1_coeffs: 8 specialized methods + generic fallback
- _compute_deriv1_coeffs!: generic barycentric fallback
- _extract_stencil_values: 2 methods
- _estimate_endpoint_derivative: 4 methods
- materialize_bc: signature + 3 passthrough methods
- Callers in cubic_solver, cubic_nd_math, quadratic_solver
@mgyoo86 mgyoo86 requested a review from Copilot February 20, 2026 21:20
@mgyoo86 mgyoo86 changed the title Feat/abstract side (breaking): new AbstractSide API replacing old Symbol-based API Feb 20, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes the migration away from Symbol-dispatched side selection for constant interpolation by introducing a typed AbstractSide hierarchy (NearestSide(), LeftSide(), RightSide()) and threading it through 1D/ND constant interpolation, PolyFit endpoint derivative estimation, and integration/show paths.

Changes:

  • Introduce and export AbstractSide + concrete side tags; replace all :left/:right/:nearest (and Val(...)) dispatch for constant interpolation with typed dispatch.
  • Update constant interpolation evaluation + ND utilities + integration kernels/APIs to accept/store typed side tags (including per-axis tuples for ND).
  • Update docs and extensive tests to the new typed side API (including show formatting expectations).

Reviewed changes

Copilot reviewed 49 out of 49 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/test_type_stability.jl Removes outdated note tied to removed side-dispatch macro in ND tests.
test/test_show.jl Updates show output expectations from :left/:nearest to LeftSide/NearestSide.
test/test_polyfit_bc.jl Migrates PolyFit endpoint-derivative tests from Val(:left/:right) to LeftSide()/RightSide().
test/test_nd_utils_shared.jl Updates _resolve_side_nd tests to typed sides; expects MethodError for Symbols.
test/test_nd_coverage.jl Updates mixed-side ND constant interpolation coverage to typed side tuples.
test/test_nd_constant.jl Updates ND constant interpolation behavioral tests to typed side keywords/tuples.
test/test_integral_series.jl Updates constant series integration tests to typed sides.
test/test_integral_nd_exactness.jl Updates ND integration exactness/finite tests to typed sides.
test/test_integral_nd.jl Updates ND integration smoke tests to typed side tuples.
test/test_integral_fulldomain.jl Updates full-domain integration tests to typed sides (1D/series/ND).
test/test_integral_extrap.jl Updates constant extrap integration tests to typed sides.
test/test_integral_allocation.jl Updates allocation tests to typed sides.
test/test_integral_1d.jl Updates 1D integration tests to typed sides.
test/test_derivatives.jl Updates constant-kernel derivative test callsite to typed side.
test/test_cumulative_integrate.jl Updates cumulative integration tests to typed sides.
test/test_constant_series_interp.jl Updates constant series API tests; verifies side is preserved as the side tag value.
test/test_constant_anchor.jl Updates anchored-query constant interpolation tests to typed sides.
test/test_constant.jl Removes macro/SideVal tests; adds AbstractSide hierarchy tests; updates invalid-side expectations.
test/test_complex_constant_series.jl Updates complex constant series side-option tests to typed sides.
test/test_complex_constant.jl Updates complex constant interpolation tests to typed sides.
test/test_coeffs.jl Updates constant coeffs tests to typed sides.
test/test_autodiff_Zygote.jl Updates Zygote constant interpolation tests to typed sides.
test/test_autodiff_ForwardDiff.jl Updates ForwardDiff constant interpolation tests to typed sides.
test/test_autodiff_Enzyme.jl Updates Enzyme constant interpolation tests to typed sides.
src/quadratic/quadratic_solver.jl Switches PolyFit BC materialization endpoint tags to typed sides.
src/integral/integrate_kernels.jl Replaces side dispatch in constant integral kernels and ND weights with typed sides.
src/integral/integrate_fulldomain.jl Simplifies constant integration paths by passing typed side directly (no manual branch).
src/integral/integrate_api.jl Simplifies constant integration API by passing typed side directly (no manual union-avoidance branch).
src/cubic/nd/cubic_nd_math.jl Switches endpoint derivative estimation to typed sides.
src/cubic/cubic_solver.jl Switches PolyFit BC materialization endpoint tags to typed sides.
src/core/utils.jl Deletes _dispatch_side and _dispatch_side_nd macros.
src/core/show.jl Updates side formatting to typed sides.
src/core/polyfit_kernels.jl Migrates endpoint derivative kernels from Val(:left/:right) to typed sides.
src/core/nd_utils.jl Replaces symbol-based _resolve_side_nd with typed-side version.
src/core/eval_ops.jl Defines AbstractSide + NearestSide/LeftSide/RightSide types.
src/core/bc_types.jl Updates materialize_bc endpoint parameter to typed side tags.
src/constant/nd/constant_nd_types.jl Updates ND constant interpolant side tuple type parameter to typed side tags.
src/constant/nd/constant_nd_oneshot.jl Updates ND oneshot APIs to accept typed sides and removes side-dispatch macro usage.
src/constant/nd/constant_nd_interpolant.jl Updates ND constructor to accept typed sides and removes Val conversion helpers.
src/constant/nd/constant_nd_eval.jl Updates generated ND kernel to accept typed side tuples and offset helpers to dispatch on types.
src/constant/constant_types.jl Stores side as a type parameter SD<:AbstractSide; constructor now accepts typed side tags.
src/constant/constant_series_interp.jl Stores series side as SD<:AbstractSide; updates internal signatures to accept typed sides.
src/constant/constant_oneshot.jl Updates 1D oneshot/in-place APIs to accept side::AbstractSide and removes side macro dispatch.
src/constant/constant_kernels.jl Migrates _constant_kernel dispatch from Val to typed side tags.
src/constant/constant_interpolant.jl Updates callable interpolant constructor signature/docs to typed sides.
src/FastInterpolations.jl Exports AbstractSide, NearestSide, LeftSide, RightSide.
docs/src/interpolation/constant.md Updates constant interpolation user docs/examples to typed sides.
docs/src/api/constant.md Documents typed side selection types and updates API examples.
README.md Updates constant interpolation examples to typed sides; aligns extrap examples with typed extrap API.
Comments suppressed due to low confidence (2)

src/core/eval_ops.jl:161

  • The docstring claims a "Union-splitting guarantee" based on there being exactly 3 AbstractSide subtypes. In this implementation, performance mostly comes from storing side as a concrete type parameter (and Tuples of concrete side types), not from union-splitting; also, AbstractSide is extensible so the “exactly 3 subtypes” assumption can be invalidated. Consider rewording this section to describe the actual mechanism (parametric/typed dispatch) and/or documenting that only NearestSide/LeftSide/RightSide are supported.
!!! info "Union-splitting guarantee"
    With exactly 3 concrete subtypes (< 4 limit), Julia union-splits
    automatically on hot paths. No manual dispatch macros needed.

test/test_polyfit_bc.jl:1815

  • The allocation reporting assigns alloc_d4 and alloc_d5 twice in a row with identical calls. This looks like an accidental duplication (the first values are overwritten immediately) and can be removed or replaced with distinct variables if two measurements are intended (e.g., warmup vs measured).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 98.76543% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.79%. Comparing base (acb6424) to head (b6d38c9).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
src/core/show.jl 75.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
- Coverage   97.84%   97.79%   -0.06%     
==========================================
  Files          71       71              
  Lines        5944     5852      -92     
==========================================
- Hits         5816     5723      -93     
- Misses        128      129       +1     
Files with missing lines Coverage Δ
src/FastInterpolations.jl 100.00% <ø> (ø)
src/constant/constant_interpolant.jl 100.00% <ø> (ø)
src/constant/constant_kernels.jl 100.00% <100.00%> (ø)
src/constant/constant_oneshot.jl 98.52% <100.00%> (-0.05%) ⬇️
src/constant/constant_series_interp.jl 95.93% <100.00%> (-0.05%) ⬇️
src/constant/constant_types.jl 100.00% <100.00%> (ø)
src/constant/nd/constant_nd_eval.jl 99.12% <100.00%> (ø)
src/constant/nd/constant_nd_interpolant.jl 100.00% <100.00%> (ø)
src/constant/nd/constant_nd_oneshot.jl 90.81% <100.00%> (-0.45%) ⬇️
src/constant/nd/constant_nd_types.jl 100.00% <ø> (ø)
... and 12 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from cleanup/remove_Symbol_extrap to master February 23, 2026 01:24
@mgyoo86 mgyoo86 merged commit a720854 into master Feb 23, 2026
8 checks passed
@mgyoo86 mgyoo86 deleted the feat/AbstractSide branch February 23, 2026 01:25
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