Propagate the units of the convolution kernel. - #35
Merged
Conversation
`convolve()` is annotated to accept a `Quantity` kernel but only ever unwrapped the unit of `array`. A `Quantity` kernel therefore reached the compiled kernels still wrapped, where Numba treats it as a plain array: with a `Quantity` array the unit of the kernel was silently dropped, and with a bare array the call failed with an `AttributeError`. Unwrap the kernel alongside the array and multiply the two units together. The convolution is a sum of products, so the product of the units is the unit of the result. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #35 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 651 677 +26
=========================================
+ Hits 651 677 +26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
convolve()is annotatedkernel: np.ndarray | u.Quantity, but only theunit of
arraywas ever unwrapped. AQuantitykernel reached the compiledkernels still wrapped, where Numba treats it as a plain array, and the
outcome depended on whether
arrayhad a unit too:The kernel is now unwrapped alongside the array and the two units are
multiplied together, so those give
mm sandsrespectively. Aconvolution is a sum of products, so the product of the units is the unit of
the result.
Tests
Added a case over the four combinations of a unitless, dimensionless, and
dimensional array and kernel, asserting the exact unit of the result and
that the values match the unitless convolution. The existing suite covers a
Quantityarray with a bare kernel.Verified locally: pytest passes (2883 tests, up from 2875), pyright reports
0 errors, and
black --checkandruff check ndfilters/are clean.🤖 Generated with Claude Code