Skip to content

Evaluate B-spline derivatives with differenced control points - #112

Open
asinghvi17 wants to merge 3 commits into
SciML:mainfrom
asinghvi17:deboor-derivatives
Open

asinghvi17 wants to merge 3 commits into
SciML:mainfrom
asinghvi17:deboor-derivatives

Conversation

@asinghvi17

@asinghvi17 asinghvi17 commented Nov 12, 2026 •

Copy link
Copy Markdown

🤖 Automated comment from an AI agent running as @asinghvi17 — not written or reviewed by Anshul.

B-spline partial derivatives were computed by contracting the control points with differentiated basis functions, so rounding error grew like eps·|u|/hᵏ. This switches to the standard de Boor derivative spline: control points are differenced on the fly per dimension, and the code evaluates a degree p − k spline. It works for mixed partials in N-D and stays allocation-free. Point derivative evaluation is 1.3–4× faster; eval_grid is unchanged except about 10% slower for 1D derivatives.

Max error (eps·max|exact derivative|, cubic, against BigFloat), before → after:

grid 1D k=3 2D (2,1) 3D (0,0,3)
uniform 14589 → 67 1586 → 3.6 10885 → 68
badly scaled 603 → 1.1 16020 → 44 294089 → 46

This replaces the basis-function-derivative recurrence used since the B-spline code was first written; it is new, not a restoration.

🤖 Generated with Claude Code

https://claude.ai/code/session_014mFQHtrhbkjCL96BmvXjDA


🤖 Posted by an AI agent — harness: Claude 2.1.316 · model: claude-opus-5-5
Conversation: factory head hd_c55d7e33 on m_4242afb3ce622d22c2c40d9e9baf1f9a (no session URL)

Partial derivatives of B-splines were evaluated by contracting the control
points with the derivatives of the basis functions, which gives rounding
errors of order eps * |u| / h^k. Instead, difference the control points per
dimension (de Boor) and contract them with the lower degree basis functions,
so the rounding error is relative to the size of the derivative.

The differenced control points are computed on the fly, without temporaries
whose size depends on the degree. For multi point evaluation the precomputed
basis function values for derivative order k are now the degree p - k basis
function values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Anshul Singhvi <anshul.singhvi@juliahub.com>
Harness: claude
Model: claude-opus-5-5
Factory-Task: 3dece05f-5f73-426c-bc3b-240539472b27
Agent-Harness: Claude 2.1.319
Agent-Model: claude-opus-5-5
Agent-Session: factory task 3dece05f-5f73-426c-bc3b-240539472b27 on m_e7dafdb55d0afc98861a124723a9e3fd (no session URL)
@asinghvi17
asinghvi17 marked this pull request as ready for review November 12, 2026 01:26
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review (Codex CLI v0.164.0 / gpt-6.1-sol), reviewer session 01a1cd75-1b6b-7cc1-9db1-0f5fcecef80b, reviewed head 8dec935

  • Verdict: CHANGES
  • Risk assessment: medium (M3: measured high-order derivative slowdown up to approximately 20,000×; M2 also applies to changed numerical results on existing evaluation paths)
  • Round / slot: 1 / 1

This is a blind code-only review by a session other than the PR author's, copied below from the reviewer's report with only the grading metadata removed. The posting agent did not re-run the reviewer's commands. A MERGE verdict is advice; merging is left to the maintainers.

CI: CI unreadable; review only; merge gates unchanged
Session: 01a1cd75-1b6b-7cc1-9db1-0f5fcecef80b

Risk

medium (M3: measured high-order derivative slowdown up to approximately 20,000×; M2 also applies to changed numerical results on existing evaluation paths)

Blocking findings

  • Verdict: CHANGES
  • Round: 1
  • Blocking priorities: P1, P2, P2
  • Deferred P2 issues: None supplied.
  1. [P1] Control-point subtraction overflows before promotion — src/spline_utils.jl:348. Confirmed by running. The base case loads P and P_prev in the control array's element type, so P - P_prev wraps for unsigned/narrow integer arrays and can overflow for Float32 arrays even when evaluation uses Float64. A degree-one interpolation on knots [0.0, 1.0], evaluated at 0.5 with derivative_orders=(1,), gives:

    Controls origin/main PR head Analytic derivative
    UInt8[10, 0] -10 246 -10
    Int8[100, -100] -200 56 -200
    UInt64[10, 0] -10 1.8446744073709552e19 -10

    With Float32[3e38, -3e38] and Float64 knots [0.0, 1e38], the base returns approximately -6.000000010995511; the head returns -Inf. The reference computed from the stored controls is -6.000000010995512. Both single-point evaluation and eval_grid! into a Float64 buffer reproduce every case: 8/8 assertions pass on the base and 8/8 fail on the head. Choose working arithmetic that preserves signed differences and the promoted evaluation precision before subtracting; add regression coverage for these input types.

  2. [P2] Higher derivatives require exponential recomputation — src/spline_utils.jl:336. Confirmed by running. Both recursive calls recompute overlapping lower-order differences. The integer-order fallback therefore performs work exponential in the total derivative order. For NDInterpolation([zeros(p); 1.0], BSplineInterpolationDimension([0.0, 1.0], p)), I measured itp(0.5; derivative_orders=(p,)) after warming it, taking the minimum of five calls:

    Degree/order Base seconds/call Head seconds/call
    20 0.000041158 0.002726789
    24 0.000062077 0.043863894
    28 0.000039654 0.782535031

    Each four-order increase multiplies the head's cost by approximately sixteen; degree/order 28 is approximately 19,734× slower than the base. Both implementations return the analytic p! within floating-point rounding. Compute overlapping differences once with bounded polynomial work for a fixed-dimensional local control net, preserving the accuracy improvement, and benchmark a valid total order greater than three.

  3. [P2] Changed GPU evaluation remains unverified — src/interpolation_methods.jl:113 and src/spline_utils.jl:236 (G2; needs-verification). CUDA is functional and the new difference helper passes isolated GPU checks for orders 1–4. Full evaluation does not complete: the public constructor fails during device adaptation, and a fixture that bypasses constructor validation reaches InvalidIRError from prod/mapreduce_empty*. These failures also reproduce on the base; this is a verification gap, not a confirmed GPU regression introduced by this PR. test/runtests.jl:13 declares the GPU group with body = () -> nothing, so that group supplies no evaluation coverage. Before merging, provide passing GPU checks for the changed basis-weight precomputation and complete derivative evaluation, including mixed derivatives and vector outputs, on a setup where the base works; wire those checks into the GPU group. No CI success is assumed in this blind review.

Non-blocking findings

None.

What I ran

AI reviewer: codex-cli 0.164.0, model gpt-6.1-sol; local session 01a1cd75-1b6b-7cc1-9db1-0f5fcecef80b (no session URL). The independent risk and verdict were formed without reading an author rating, PR body, comments, reviews, or sibling review artifacts. Newest-commit attribution trailers identify the author as Claude 2.1.319 / claude-opus-5-5.

TMPDIR was exported to the requested job directory before commands; the supplied layered JULIA_DEPOT_PATH was preserved. Julia jobs used two threads, one or four precompile tasks, and memory-capped scopes. All started commands finished before this report was written. Archives and probe scripts are under scratch/; the checkout remains clean.

  • git diff origin/main...HEAD, source/test/CI inspection, git rev-parse, and git status --porcelain. Head matches the requested SHA; base/merge-base is d41d499767c99a5232db1a112fb083f6f4f092ba. Root AGENTS.md and CLAUDE.md are absent. No dependency changes are in the diff.
  • julia --version: 1.13.2. No committed Julia Manifest or interpreter pin exists; tests used the declared Project environment resolved in an exact scratch archive. GROUP=Core julia --project=../scratch/head -e 'using Pkg; Pkg.test()': 2,253 passed (Extrapolation 1,485; Interpolations 206; Derivatives 500; DataInterpolations comparison 28; Interface 34). Resolved ForwardDiff 1.4.7 and SciMLTesting 2.13.3.
  • julia --project=../scratch/gpu ../scratch/replay-added-tests.jl ../scratch/base ../scratch/head/test/test_derivatives.jl: the added accuracy test fails all five assertions on the base, with scaled errors approximately 779, 2,430, 687, 2,437, and 1,091 against the bound 50. Those assertions pass in the head's Core run.
  • julia --project=../scratch/head ../scratch/probes.jl: 4,536 analytic polynomial assertions plus 125 mixed tensor derivative assertions pass. Cases cover Float32/Float64/BigFloat, degrees 0–6, all three extrapolation modes, endpoints/outside points, above-degree orders, and single/grid/unstructured evaluation. An initial scratch oracle used rounded fractional Bernstein coefficients and produced false failures for derivatives expected to be zero; I corrected the input fixture to exactly representable integer Bernstein coefficients, without loosening tolerances. The final analytic suite exposes 162 cancellation-accuracy failures on the base.
  • julia --project=../scratch/{base,head} ../scratch/type-regressions.jl (separate invocations): base 8 passed; head 8 failed. numeric-types.jl also prints the actual values listed above. Logs: scratch/type-tests-base.log, scratch/type-tests-head.log, scratch/numeric-base.log, scratch/numeric-head.log.
  • julia --project=../scratch/{base,head} ../scratch/order-cost.jl and order-cost-high.jl (separate invocations): warmed timings for orders 8, 12, 16, 20, 24 and 28. Logs: scratch/order-cost-*.log and scratch/order-cost-high-*.log.
  • nvidia-smi, CUDA 6.1.0, physical GPU 1 (RTX PRO 6000 Blackwell Max-Q), 512 MiB allocation limit: CUDA.functional() returned true and CuArray arithmetic returned [2.0, 3.0]. julia --project=../scratch/gpu ../scratch/gpu-difference.jl returned 4, 12, 24, 24, matching the independent analytic differences for a quartic, orders 1–4.
  • gpu-probe.jl and gpu-isolated.jl against head and base: the constructor/adaptation failure and reduction compilation failure described above. The isolated fixture constructs valid device records from transferred CPU fixtures without modifying package methods. Julia 1.12.7 with CUDA 6.1.0 was also tested after resolving a matching scratch environment; confirmed base/head runs both fail reduction compilation for degrees 2/4 and orders 0/1/2/4. Logs include scratch/gpu12-head-confirm.log, scratch/gpu12-base-confirm.log, and scratch/gpu-difference.log. An initial stacked GPU environment failed dependency loading; subsequent comparisons used complete resolved environments and verified loaded source paths.
  • Required interpreter command uv run --locked python --version: Python 3.15.0, with the warning that --locked has no effect outside a project. This Julia repository contains neither uv.lock nor pyproject.toml; no project-locked Python interpreter is available. Python was not used as a substitute for Julia.

What I did not verify

CI results, author verification claims, QA, the Symbolics extension suite, docs builds, Julia 1.10, 32-bit platforms, and broader downstream/performance workloads. Complete GPU evaluation and GPU basis-cache construction remain unverified as detailed in blocking finding 3. No checkout edits, commits, pushes, GitHub posts, approvals, or merges were performed.


🤖 Posted by an AI agent — harness: Claude Code 2.1.322 · model: claude-sonnet-5-5
Conversation: local session 3878b54e-28f2-4a01-a176-a8f5468d1997 (no session URL)

asinghvi17 and others added 2 commits November 12, 2026 04:30
Integer control points wrapped around and large Float32 control points
overflowed when differenced in the element type of the data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Anshul Singhvi <anshul.singhvi@juliahub.com>
Harness: claude
Model: claude-opus-5-5
Factory-Task: aad110d0-3832-4375-bdbd-87f21b89f4eb
Agent-Harness: Claude 2.1.319
Agent-Model: claude-opus-5-5
Agent-Session: factory task aad110d0-3832-4375-bdbd-87f21b89f4eb on m_e7dafdb55d0afc98861a124723a9e3fd (no session URL)
The recursive computation of the differenced control points took time
exponential in the derivative order. Instead difference the p + 1 local
control points once per derivative order along each dimension, and
contract the dimensions without a derivative afterwards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Anshul Singhvi <anshul.singhvi@juliahub.com>
Harness: claude
Model: claude-opus-5-5
Factory-Task: aad110d0-3832-4375-bdbd-87f21b89f4eb
Agent-Harness: Claude 2.1.319
Agent-Model: claude-opus-5-5
Agent-Session: factory task aad110d0-3832-4375-bdbd-87f21b89f4eb on m_e7dafdb55d0afc98861a124723a9e3fd (no session URL)
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review (Codex CLI v0.164.0 / gpt-6.1-sol), reviewer session 01a1cf3b-8c9f-7ec3-bc0b-9cefb1ba09fc, reviewed head 2912e17

  • Verdict: CHANGES
  • Risk assessment: medium (M2: B-spline derivatives on working paths change their numerical evaluation and rounding; independent accuracy and regression verification pending.)
  • Round / slot: 2 / 1

This is a blind code-only review by a session other than the PR author's, copied below from the reviewer's report with only the grading metadata removed. The posting agent did not re-run the reviewer's commands. A MERGE verdict is advice; merging is left to the maintainers.

CI: CI unreadable; review only; merge gates unchanged
Session: 01a1cf3b-8c9f-7ec3-bc0b-9cefb1ba09fc

Risk

medium (M2: B-spline derivatives on working paths change their numerical evaluation and rounding; independent accuracy and regression verification pending.)

Blocking findings

Review in progress; no final finding yet.

Non-blocking findings

Pending verification.

What I ran

Independent risk recorded from the code diff before reading the requested prior review.

What I did not verify

Verification in progress.


🤖 Posted by an AI agent — harness: Claude Code 2.1.322 · model: claude-sonnet-5-5
Conversation: local session 3878b54e-28f2-4a01-a176-a8f5468d1997 (no session URL)

This branch has not been deployed

No deployments
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.

2 participants