Fix nchannels fallback for wrapped images (e.g., Adjoint / PermutedDimsArray) - #194
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #194 +/- ##
==========================================
+ Coverage 93.37% 93.48% +0.10%
==========================================
Files 15 15
Lines 1192 1181 -11
==========================================
- Hits 1113 1104 -9
+ Misses 79 77 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Owner
|
I think this is reasonable, thanks for the PR! The failures on the nightlies seem to be related to #193. |
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.
Description
This PR fixes an issue where calling
nchannels()on an image that has been wrapped (such as withadjoint(') orPermutedDimsArray) incorrectly returns the total length of the array (the number of pixels) instead of the actual number of image channels.The Bug
Currently, if a user loads a multi-channel image and applies an operation that changes the array type (like
img'),nchannelsfalls back to the generic method:nchannels(x) = _length(x)Because the wrapped image is evaluated as a generic
AbstractArray,_length(x)calculates the total number of elements in the matrix (e.g.,rows * cols), leading to wildly incorrect results like returning4186for a 2-channel 91x46 image.The Fix
By adding a dispatch for
AbstractArray{<:ColorOrTuple}, we ensure that any wrapped array containing colorants or tuples correctly delegates thenchannelscall to itseltype, preserving the expected behavior:Reproducible Example & Tests
This PR ensures all tests pass, even when the arrays are wrapped with
adjoint: