Skip to content

Refactor polynomial for Hermite#60

Merged
kylebeggs merged 19 commits intomainfrom
cleanup
Jan 5, 2026
Merged

Refactor polynomial for Hermite#60
kylebeggs merged 19 commits intomainfrom
cleanup

Conversation

@kylebeggs
Copy link
Member

closes #48 and includes other refactors so we dispatch at a lower level than _build_collocation_matrix!, etc. allowing us to simplify, remove some duplicated code in stencil_math.jl

@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 90.15748% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/operators/operators.jl 72.13% 17 Missing ⚠️
src/operators/custom.jl 0.00% 6 Missing ⚠️
src/operators/gradient.jl 60.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
src/RadialBasisFunctions.jl 100.00% <ø> (ø)
src/basis/gaussian.jl 100.00% <100.00%> (ø)
src/basis/inverse_multiquadric.jl 100.00% <100.00%> (ø)
src/basis/polyharmonic_spline.jl 100.00% <100.00%> (ø)
src/operators/directional.jl 100.00% <100.00%> (+2.17%) ⬆️
src/operators/jacobian.jl 100.00% <100.00%> (ø)
src/solve/api.jl 100.00% <ø> (ø)
src/solve/assembly.jl 100.00% <100.00%> (ø)
src/solve/execution.jl 99.00% <100.00%> (ø)
src/solve/types.jl 97.10% <100.00%> (+0.04%) ⬆️
... and 3 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 15, 2025

Benchmark Results

main 9ba7549... main / 9ba7549...
Directional 2.4 ± 0.13 ms 2.32 ± 0.11 ms 1.04 ± 0.073
Directional (per point) 2.4 ± 0.081 ms 2.33 ± 0.097 ms 1.03 ± 0.055
Gradient 7.3 ± 0.21 ms 7.78 ± 0.36 ms 0.938 ± 0.051
MonomialBasis/dim=1/deg=0 0.0464 ± 0.012 μs 0.0468 ± 0.011 μs 0.991 ± 0.36
MonomialBasis/dim=1/deg=1 0.075 ± 0.013 μs 0.0744 ± 0.011 μs 1.01 ± 0.23
MonomialBasis/dim=1/deg=2 0.0851 ± 0.018 μs 0.0871 ± 0.018 μs 0.976 ± 0.29
MonomialBasis/dim=2/deg=0 0.0371 ± 0.011 μs 0.0371 ± 0.012 μs 1 ± 0.44
MonomialBasis/dim=2/deg=1 0.0359 ± 0.011 μs 0.0373 ± 0.012 μs 0.961 ± 0.42
MonomialBasis/dim=2/deg=2 0.0423 ± 0.01 μs 0.0434 ± 0.012 μs 0.974 ± 0.35
MonomialBasis/dim=3/deg=0 0.0344 ± 0.011 μs 0.0349 ± 0.012 μs 0.986 ± 0.47
MonomialBasis/dim=3/deg=1 0.0421 ± 0.011 μs 0.0421 ± 0.011 μs 1 ± 0.37
MonomialBasis/dim=3/deg=2 0.0483 ± 0.012 μs 0.0481 ± 0.012 μs 1 ± 0.35
Partial 2.42 ± 0.097 ms 2.32 ± 0.11 ms 1.04 ± 0.064
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 0/0/∂ 10.3 ± 0.091 ns 10.3 ± 0.12 ns 0.996 ± 0.015
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 0/0/∂² 10.5 ± 0.051 ns 10.6 ± 0.099 ns 0.997 ± 0.011
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 0/0/∇ 17.3 ± 0.06 ns 17.3 ± 0.06 ns 1 ± 0.0049
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 0/0/∇² 18.3 ± 0.05 ns 18.6 ± 0.16 ns 0.985 ± 0.0089
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 1/1/∂ 10.3 ± 0.08 ns 10.3 ± 0.09 ns 0.997 ± 0.012
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 1/1/∂² 10.6 ± 0.059 ns 10.6 ± 0.1 ns 1 ± 0.011
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 1/1/∇ 17.3 ± 0.06 ns 17.3 ± 0.06 ns 1 ± 0.0049
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 1/1/∇² 18.3 ± 0.05 ns 18.7 ± 0.18 ns 0.983 ± 0.0099
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 2/2/∂ 10.3 ± 0.07 ns 10.3 ± 0.081 ns 0.998 ± 0.01
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 2/2/∂² 10.6 ± 0.07 ns 10.6 ± 0.08 ns 1 ± 0.01
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 2/2/∇ 17.3 ± 0.06 ns 17.3 ± 0.06 ns 1 ± 0.0049
RBF/Gaussian, exp(-(ε*r)²)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 2/2/∇² 18.3 ± 0.05 ns 18.7 ± 0.18 ns 0.984 ± 0.0099
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 0/0/∂ 6.8 ± 0.051 ns 6.74 ± 0.15 ns 1.01 ± 0.024
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 0/0/∂² 14.2 ± 0.081 ns 14.1 ± 0.25 ns 1.01 ± 0.019
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 0/0/∇ 8.38 ± 0.07 ns 8.48 ± 0.28 ns 0.988 ± 0.034
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 0/0/∇² 16.2 ± 0.031 ns 16.4 ± 0.12 ns 0.987 ± 0.0075
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 1/1/∂ 6.72 ± 0.15 ns 6.8 ± 0.14 ns 0.988 ± 0.03
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 1/1/∂² 14.2 ± 0.08 ns 14 ± 0.31 ns 1.02 ± 0.023
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 1/1/∇ 8.4 ± 0.11 ns 8.51 ± 0.29 ns 0.987 ± 0.036
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 1/1/∇² 16.2 ± 0.08 ns 16.4 ± 0.091 ns 0.987 ± 0.0073
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 2/2/∂ 6.73 ± 0.16 ns 6.8 ± 0.14 ns 0.99 ± 0.031
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 2/2/∂² 14.2 ± 0.08 ns 14.1 ± 0.11 ns 1.01 ± 0.0098
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 2/2/∇ 8.37 ± 0.051 ns 8.52 ± 0.29 ns 0.982 ± 0.034
RBF/Inverse Multiquadrics, 1/sqrt((r*ε)²+1)
├─Shape factor: ε = 1
└─Polynomial augmentation: degree 2/2/∇² 16.2 ± 0.03 ns 16.4 ± 0.09 ns 0.987 ± 0.0057
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 0/0/∂ 3.73 ± 0.01 ns 3.72 ± 0.01 ns 1 ± 0.0038
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 0/0/∂² 4.74 ± 0.05 ns 4.7 ± 0.011 ns 1.01 ± 0.011
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 0/0/∇ 5.43 ± 0.02 ns 5.41 ± 0.02 ns 1 ± 0.0052
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 0/0/∇² 3.42 ± 0.011 ns 3.42 ± 0.01 ns 1 ± 0.0044
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 1/1/∂ 3.73 ± 0.01 ns 3.72 ± 0.01 ns 1 ± 0.0038
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 1/1/∂² 4.71 ± 0.02 ns 4.7 ± 0.011 ns 1 ± 0.0049
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 1/1/∇ 5.43 ± 0.011 ns 5.41 ± 0.02 ns 1 ± 0.0042
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 1/1/∇² 3.42 ± 0.011 ns 3.42 ± 0.01 ns 1 ± 0.0044
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 2/2/∂ 3.73 ± 0.01 ns 3.72 ± 0.01 ns 1 ± 0.0038
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 2/2/∂² 4.73 ± 0.061 ns 4.7 ± 0.011 ns 1.01 ± 0.013
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 2/2/∇ 5.43 ± 0.02 ns 5.41 ± 0.02 ns 1 ± 0.0052
RBF/Polyharmonic spline (r³)
└─Polynomial augmentation: degree 2/2/∇² 3.42 ± 0.011 ns 3.42 ± 0.01 ns 1 ± 0.0044
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 0/0/∂ 4.27 ± 0.01 ns 4.27 ± 0.01 ns 1 ± 0.0033
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 0/0/∂² 5.75 ± 0.01 ns 5.82 ± 0.06 ns 0.988 ± 0.01
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 0/0/∇ 6.36 ± 0.031 ns 6.77 ± 0.05 ns 0.939 ± 0.0083
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 0/0/∇² 4.27 ± 0.009 ns 4.27 ± 0.01 ns 1 ± 0.0032
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 1/1/∂ 4.27 ± 0.01 ns 4.27 ± 0.01 ns 1 ± 0.0033
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 1/1/∂² 5.75 ± 0.01 ns 5.83 ± 0.09 ns 0.986 ± 0.015
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 1/1/∇ 6.72 ± 0.05 ns 6.76 ± 0.04 ns 0.994 ± 0.0094
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 1/1/∇² 4.27 ± 0.009 ns 4.27 ± 0.01 ns 1 ± 0.0032
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 2/2/∂ 4.27 ± 0.01 ns 4.27 ± 0.01 ns 1 ± 0.0033
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 2/2/∂² 5.74 ± 0.011 ns 5.82 ± 0.05 ns 0.986 ± 0.0087
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 2/2/∇ 6.36 ± 0.04 ns 6.76 ± 0.049 ns 0.941 ± 0.009
RBF/Polyharmonic spline (r¹)
└─Polynomial augmentation: degree 2/2/∇² 4.27 ± 0.01 ns 4.27 ± 0.01 ns 1 ± 0.0033
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 0/0/∂ 4.96 ± 0.011 ns 4.65 ± 0.01 ns 1.07 ± 0.0033
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 0/0/∂² 4.96 ± 0.011 ns 5.26 ± 0.01 ns 0.943 ± 0.0028
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 0/0/∇ 5.95 ± 0.08 ns 5.95 ± 0.09 ns 1 ± 0.02
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 0/0/∇² 3.42 ± 0.01 ns 3.11 ± 0 ns 1.1 ± 0.0032
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 1/1/∂ 4.96 ± 0.011 ns 4.65 ± 0.01 ns 1.07 ± 0.0033
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 1/1/∂² 4.96 ± 0.01 ns 5.27 ± 0.01 ns 0.941 ± 0.0026
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 1/1/∇ 5.93 ± 0.089 ns 5.96 ± 0.09 ns 0.995 ± 0.021
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 1/1/∇² 3.42 ± 0.01 ns 3.11 ± 0 ns 1.1 ± 0.0032
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 2/2/∂ 4.96 ± 0.011 ns 4.65 ± 0.01 ns 1.07 ± 0.0033
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 2/2/∂² 4.96 ± 0.01 ns 5.26 ± 0.01 ns 0.943 ± 0.0026
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 2/2/∇ 5.93 ± 0.09 ns 5.95 ± 0.081 ns 0.997 ± 0.02
RBF/Polyharmonic spline (r⁵)
└─Polynomial augmentation: degree 2/2/∇² 3.42 ± 0.01 ns 3.11 ± 0 ns 1.1 ± 0.0032
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 0/0/∂ 10.5 ± 0.031 ns 10.5 ± 0.08 ns 1 ± 0.0082
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 0/0/∂² 4.96 ± 0.001 ns 4.96 ± 0.01 ns 1 ± 0.002
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 0/0/∇ 12.5 ± 0.1 ns 12.4 ± 0.091 ns 1 ± 0.011
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 0/0/∇² 8.55 ± 0.14 ns 8.54 ± 0.14 ns 1 ± 0.023
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 1/1/∂ 10.5 ± 0.051 ns 10.5 ± 0.08 ns 0.999 ± 0.009
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 1/1/∂² 4.96 ± 0.001 ns 4.96 ± 0.01 ns 1 ± 0.002
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 1/1/∇ 12.5 ± 0.11 ns 12.4 ± 0.1 ns 1 ± 0.012
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 1/1/∇² 8.54 ± 0.14 ns 8.54 ± 0.14 ns 1 ± 0.023
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 2/2/∂ 10.5 ± 0.051 ns 10.5 ± 0.041 ns 0.998 ± 0.0062
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 2/2/∂² 4.96 ± 0.001 ns 4.96 ± 0.01 ns 1 ± 0.002
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 2/2/∇ 12.5 ± 0.099 ns 0.0464 ± 0.00022 μs 0.268 ± 0.0025
RBF/Polyharmonic spline (r⁷)
└─Polynomial augmentation: degree 2/2/∇² 8.54 ± 0.14 ns 8.54 ± 0.14 ns 0.999 ± 0.023
time_to_load 0.611 ± 0.0053 s 0.601 ± 0.001 s 1.02 ± 0.009

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

kylebeggs and others added 13 commits December 15, 2025 18:40
Replace runtime if-statements with Julia multiple dispatch for the
normal parameter in PHS derivative functions. Split each function
into two methods: one for Nothing (standard derivative) and one for
AbstractVector (Hermite/directional derivative).

Also adds AVOID_INF consistently to prevent division by zero.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update operator implementations and tests for jacobian/gradient
functionality. Includes documentation updates and test refinements.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Jacobian operator and autodiff support
Copy link
Member

@Davide-Miotti Davide-Miotti left a comment

Choose a reason for hiding this comment

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

The refactored part looks very good, I'm missing the ext/ part, because I need a bit more context. I only suggested a further simplification of the operators interface, we might leave it as is for now, but in the future all this code repetition might hinder further development.

Copy link
Member

Choose a reason for hiding this comment

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

It seems to me like we are having a lot of code repetition between different operators, most of the code remains the same with very subtle changes. You already cleaned it up a lot and it is very clear but I feel like we can simplify it further and make it really great. Using Claude I tried to find a way to get rid of these repetitions and after some trial and error it came up with what is written inside OPERATOR_REFACTORING_IDEAS.md (it is actually a single idea). I pushed it to this branch so that it remains saved even if you ask claude to refine it before implementing.

Copy link
Member

Choose a reason for hiding this comment

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

Great job here, the script is long but it really is well refactored now

@kylebeggs kylebeggs merged commit b429bc7 into main Jan 5, 2026
25 of 26 checks passed
@kylebeggs kylebeggs deleted the cleanup branch January 5, 2026 03:58
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.

improve handling of polynomial terms

2 participants