-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix mapwindow for offset arrays #160
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
77cb511
Fix mapwindow for offset arrays
yha ef313e0
Fix assuming merging of OffsetArrays#105 (IdOffsetRange preserve indi…
yha 92a4aa8
Fix output axes for border=Inner(), test with anonymous functions
yha 31c3312
update OffsetArrays dependency
johnnychen94 7663f48
Merge branch 'master' into mapwindow-offset
johnnychen94 5bab482
Clearer comment. Fix eltype in _indexof.
yha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,33 @@ using ImageFiltering: IdentityUnitRange | |
Amin = groundtruth(min, A, w) | ||
@test minval == Amin | ||
end | ||
# offsets | ||
@testset "offsets" begin | ||
n = 5 | ||
arrays = [rand(n), rand(n,n), rand(n,n,n)] | ||
@testset "offsets ($f, $offset, $window, $dim)" for f in (extrema,maximum,minimum), | ||
offset in -5:5, | ||
window in [1:2:9; [0:2,-2:0]], | ||
# broken: "reflect", NA(), NoPad() | ||
border in ["replicate", "symmetric", Fill(randn()), Inner()], | ||
(dim,a) in enumerate(arrays) | ||
offsets = ntuple(_->offset,dim) | ||
windows = ntuple(_->window,dim) | ||
winlen = window isa Number ? window : length(window) | ||
wrapped_f = x->f(x) | ||
for g in (f, wrapped_f) | ||
mw(a) = mapwindow(g, a, windows, border=border) | ||
|
||
if border == Inner() && winlen > n | ||
@test_throws DimensionMismatch mw(a) | ||
@test_throws DimensionMismatch mw(OffsetArray(a,offsets)) | ||
else | ||
@test OffsetArray(mw(a),offsets) == mw(OffsetArray(a,offsets)) | ||
end | ||
end | ||
end | ||
end | ||
johnnychen94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
# median | ||
for f in (median, median!) | ||
|
@@ -115,7 +142,7 @@ using ImageFiltering: IdentityUnitRange | |
@test expected == @inferred mapwindow!(f,out,img,window,indices=imginds) | ||
end | ||
for (inds, kw) ∈ [((Base.OneTo(3),), (border="replicate", indices=2:2:7)), | ||
((2:7,), (indices=2:7,)), | ||
(axes(2:7), (indices=2:7,)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not have an opinion on whether this is a bug fix or breaking change. |
||
((Base.OneTo(10),), ()) | ||
] | ||
@test inds == axes(mapwindow(mean, randn(10), (3,); kw...)) | ||
|
@@ -130,6 +157,8 @@ using ImageFiltering: IdentityUnitRange | |
@test mapwindow(first, img_48, (0:2,), | ||
border=Inner(), | ||
indices=inds_48) == img_48[inds_48] | ||
res_shifted = mapwindow(minimum, img_48, -2:0, border=Inner()) | ||
@test res_shifted == OffsetArray(img_48[1:8], 3:10) | ||
|
||
@testset "desugaring window argument #58" begin | ||
img58 = rand(10) | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not exactly sure I understand what you're trying to do. It doesn't quite do what it claims in the comment, for example
What's the underlying goal? Would you like to create a range that preserves the values and indices of an original
AbstractUnitRange
but which behaves as described under broadcasting?Or is this a situation where we can essentially ignore certain axes? For instance, we might imagine ignoring the axes of
imginds
, although alternatively they might specify the axes of the output.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the comment is confusing because it uses the name
r
for the output of the function when it's also as the name of the function parameter. It should really say thats = self_offset(r)
has the same values asr
but has itself as indices:collect(s) == collect(r)
andaxes(s) == (s,)
(in your example,axes(r3) == (2:7,) == (r3,)
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the comment