Skip to content
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

deprecate invwarpedview in favor of InvWarpedView #138

Merged
merged 3 commits into from
Aug 19, 2021

Conversation

johnnychen94
Copy link
Member

@johnnychen94 johnnychen94 commented Jul 18, 2021

Should be the last PR before v0.9 release.

Now that InvWarpedView accepts method and fillvalue keywords, and also commits to the parent(wv) === img assumption. (This is also an improvement to #24 and thus makes invwarpedview not really necessary.)

This also introduces the same set of already deprecated API to keep consistent with warpedview, e.g., InvWarpedView(img, tinv, inds, method, fillvalue) is newly added as a deprecated method.

Other unrelated changes:

  • propagate @inbounds for getindex method for both WarpedView and InvWarpedView
  • simplify Base.size methods and remove IndexStyle; it's sufficient to use the fallback implementation in Base.

TODO:

  • bring the SubArray trick back appropriately (This trick is directly removed)

This also introduces the same set of already deprecated API to keep
consistant with `warpedview`, e.g.,
`InvWarpedView(img, tinv, inds, method, fillvalue)` is newly added
as deprecated method.
@codecov
Copy link

codecov bot commented Jul 18, 2021

Codecov Report

Merging #138 (36e9ea8) into master (eeee0bf) will decrease coverage by 1.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #138      +/-   ##
==========================================
- Coverage   92.15%   91.09%   -1.06%     
==========================================
  Files           8        8              
  Lines         204      191      -13     
==========================================
- Hits          188      174      -14     
- Misses         16       17       +1     
Impacted Files Coverage Δ
src/compat.jl 80.00% <ø> (ø)
src/warp.jl 100.00% <ø> (ø)
src/invwarpedview.jl 84.00% <100.00%> (-13.15%) ⬇️
src/warpedview.jl 94.11% <100.00%> (+9.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eeee0bf...36e9ea8. Read the comment docs.

@timholy
Copy link
Member

timholy commented Aug 19, 2021

This seems reasonable. One distinction between InvWarpedView and invwarpedview is that the first should be a constructor and always return an InvWarpedView. The second would have license to, e.g., strip a WarpedView wrapper that happens to be inverted from the one being applied. That's probably a corner case that would only arise by design rather than in "real" usage.

@johnnychen94
Copy link
Member Author

johnnychen94 commented Aug 19, 2021

The more concerning issue I find with this trick with this "license" to merge two or more lazy warp views through SubArray is that out-of-domain values are not guaranteed to be valid. This can be a deeply buried root of potential bugs so I choose to remove this to make things easier to intuit.

img_camera = testimage("cameraman")
img = similar(img_camera) # uninitialized array
v = view(img, 75:195, 245:370)
v .= img_camera[v.indices...]

tfm = recenter(RotMatrix(-pi/8), center(img_camera))
wrong_result = collect(invwarpedview(v, tfm)) # there's no way to check if `parent(v)` are filled with real useful data.
correct_result = collect(InvWarpedView(v, tfm))
mosaic(wrong_result, correct_result; nrow=1)

image

wrong_result = collect(invwarpedview(v, tfm, axes(v)))
correct_result = collect(InvWarpedView(v, tfm, axes(v)))
mosaic(wrong_result, correct_result; nrow=1)

image

It should be the caller's responsibility to check whether this optimization is valid and not the callee invwarpedview/warpedview.

@timholy
Copy link
Member

timholy commented Aug 19, 2021

I like this way of thinking! 100% agreed.

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