Skip to content

Add __array_ufunc__ to ADF for NumPy ufunc dispatch#24

Merged
saudzahirr merged 1 commit into
masterfrom
fix/numpy-ufunc-dispatch
May 19, 2026
Merged

Add __array_ufunc__ to ADF for NumPy ufunc dispatch#24
saudzahirr merged 1 commit into
masterfrom
fix/numpy-ufunc-dispatch

Conversation

@saudzahirr
Copy link
Copy Markdown
Member

@saudzahirr saudzahirr commented May 19, 2026

Summary

Closes #12.

  • Adds __array_ufunc__ to ADF so that NumPy math ufuncs (e.g. numpy.sin(x), numpy.exp(x)) dispatch to their admath equivalents when called on ADF objects — the issue reported in Add ad.math functions to ADF objects. #12.
  • Also handles arithmetic ufuncs (numpy.multiply, numpy.add, etc.) element-wise using Python-level operators, preserving the pre-existing behaviour of numpy_array * adf_scalar returning an object array with derivative tracking intact.
  • Raises max-public-methods to 25 in ruff config to accommodate the new dunder method.

Test plan

  • All 18 existing tests pass (pytest tests/ -v)
  • np.sin(adnumber(1.0)) returns an ADF with correct derivative
  • np.logspace(0, 4, 5) * adnumber(2) returns an object array of ADF values with correct derivatives

🤖 Generated with Claude Code

Enables numpy math functions (numpy.sin, numpy.cos, etc.) to dispatch
directly to their admath equivalents when called on ADF objects.
Also handles arithmetic ufuncs (numpy.multiply, numpy.add, etc.)
element-wise to preserve existing numpy array * ADF behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@saudzahirr saudzahirr merged commit 6b3279b into master May 19, 2026
18 checks passed
@saudzahirr saudzahirr deleted the fix/numpy-ufunc-dispatch branch May 19, 2026 18:38
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.

Add ad.math functions to ADF objects.

1 participant