Skip to content

Commit e1ef518

Browse files
authored
deprecate invwarpedview in favor of InvWarpedView (#138)
* deprecate `invwarpedview` in favor of `InvWarpedView` * remove `SubArray` method for `invwarpedview`
1 parent eeee0bf commit e1ef518

File tree

11 files changed

+84
-170
lines changed

11 files changed

+84
-170
lines changed

docs/src/reference.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ ImageTransformations.imresize
1515
ImageTransformations.warp
1616
ImageTransformations.WarpedView
1717
ImageTransformations.InvWarpedView
18-
ImageTransformations.invwarpedview
1918
```
2019

2120
# Utilities

src/compat.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
# - Codes for backward compatibility
33
# - Glue codes that might no longer be necessary in the future
44

5-
@static if !isdefined(Base, :IdentityUnitRange)
6-
const IdentityUnitRange = Base.Slice
7-
else
8-
using Base: IdentityUnitRange
9-
end
10-
115
@static if VERSION < v"1.1"
126
@inline isnothing(x) = x === nothing
137
end

src/deprecated.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
@deprecate WarpedView(img::AbstractArray, tform::Transformation, inds, fillvalue::FillType, method::MethodType) WarpedView(img, tform, inds; method=method, fillvalue=fillvalue)
2929

3030
@deprecate warpedview(args...; kwargs...) WarpedView(args...; kwargs...)
31+
@deprecate invwarpedview(args...; kwargs...) InvWarpedView(args...; kwargs...)
3132

32-
@deprecate invwarpedview(img::AbstractArray, tinv::Transformation, method::MethodType, ) invwarpedview(img, tinv; method=method)
33-
@deprecate invwarpedview(img::AbstractArray, tinv::Transformation, fillvalue::FillType) invwarpedview(img, tinv; fillvalue=fillvalue)
34-
@deprecate invwarpedview(img::AbstractArray, tinv::Transformation, method::MethodType, fillvalue::FillType) invwarpedview(img, tinv; method=method, fillvalue=fillvalue)
35-
@deprecate invwarpedview(img::AbstractArray, tinv::Transformation, fillvalue::FillType, method::MethodType) invwarpedview(img, tinv; method=method, fillvalue=fillvalue)
36-
@deprecate invwarpedview(img::AbstractArray, tinv::Transformation, inds, method::MethodType, ) invwarpedview(img, tinv, inds; method=method)
37-
@deprecate invwarpedview(img::AbstractArray, tinv::Transformation, inds, fillvalue::FillType) invwarpedview(img, tinv, inds; fillvalue=fillvalue)
38-
@deprecate invwarpedview(img::AbstractArray, tinv::Transformation, inds, method::MethodType, fillvalue::FillType) invwarpedview(img, tinv, inds; method=method, fillvalue=fillvalue)
39-
@deprecate invwarpedview(img::AbstractArray, tinv::Transformation, inds, fillvalue::FillType, method::MethodType) invwarpedview(img, tinv, inds; method=method, fillvalue=fillvalue)
33+
@deprecate InvWarpedView(img::AbstractArray, tinv::Transformation, method::MethodType, ) InvWarpedView(img, tinv; method=method)
34+
@deprecate InvWarpedView(img::AbstractArray, tinv::Transformation, fillvalue::FillType) InvWarpedView(img, tinv; fillvalue=fillvalue)
35+
@deprecate InvWarpedView(img::AbstractArray, tinv::Transformation, method::MethodType, fillvalue::FillType) InvWarpedView(img, tinv; method=method, fillvalue=fillvalue)
36+
@deprecate InvWarpedView(img::AbstractArray, tinv::Transformation, fillvalue::FillType, method::MethodType) InvWarpedView(img, tinv; method=method, fillvalue=fillvalue)
37+
@deprecate InvWarpedView(img::AbstractArray, tinv::Transformation, inds, method::MethodType, ) InvWarpedView(img, tinv, inds; method=method)
38+
@deprecate InvWarpedView(img::AbstractArray, tinv::Transformation, inds, fillvalue::FillType) InvWarpedView(img, tinv, inds; fillvalue=fillvalue)
39+
@deprecate InvWarpedView(img::AbstractArray, tinv::Transformation, inds, method::MethodType, fillvalue::FillType) InvWarpedView(img, tinv, inds; method=method, fillvalue=fillvalue)
40+
@deprecate InvWarpedView(img::AbstractArray, tinv::Transformation, inds, fillvalue::FillType, method::MethodType) InvWarpedView(img, tinv, inds; method=method, fillvalue=fillvalue)
4041

4142
# END 0.9 deprecations

src/invwarpedview.jl

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
"""
2-
InvWarpedView(img, tinv, [indices]) -> wv
2+
InvWarpedView(img, tinv, [indices]; kwargs...) -> wv
3+
InvWarpedView(inner_view, tinv) -> wv
34
45
Create a view of `img` that lazily transforms any given index `I`
56
passed to `wv[I]` so that `wv[I] == img[inv(tinv)(I)]`.
67
8+
Except for the lazy evaluation, the following two lines are expected to be equivalent:
9+
10+
```julia
11+
warp(img, inv(tform), [indices]; kwargs...)
12+
invwarpedview(img, tform, [indices]; kwargs...)
13+
```
14+
715
The conceptual difference to [`WarpedView`](@ref) is that
816
`InvWarpedView` is intended to be used when reasoning about the
917
image is more convenient that reasoning about the indices.
1018
Furthermore, `InvWarpedView` allows simple nesting of
1119
transformations, in which case the transformations will be
1220
composed into a single one.
1321
14-
See [`invwarpedview`](@ref) for a convenient constructor of `InvWarpedView`.
15-
1622
For detailed explaination of warp, associated arguments and parameters,
1723
please refer to [`warp`](@ref).
1824
"""
@@ -26,8 +32,9 @@ function InvWarpedView(inner::WarpedView{T,N,TA,F,I,E}) where {T,N,TA,F,I,E}
2632
InvWarpedView{T,N,TA,F,I,typeof(tinv),E}(inner, tinv)
2733
end
2834

29-
function InvWarpedView(A::AbstractArray, tinv::Transformation, inds::Tuple = autorange(A, tinv))
30-
InvWarpedView(WarpedView(A, inv(tinv), inds), tinv)
35+
function InvWarpedView(A::AbstractArray, tinv::Transformation, inds::Tuple = autorange(A, tinv); kwargs...)
36+
inner = WarpedView(A, inv(tinv), inds; kwargs...)
37+
InvWarpedView(inner, tinv)
3138
end
3239

3340
function InvWarpedView(inner::InvWarpedView, outer_tinv::Transformation)
@@ -40,14 +47,11 @@ function InvWarpedView(inner::InvWarpedView, outer_tinv::Transformation, inds::T
4047
InvWarpedView(parent(inner), tinv, inds)
4148
end
4249

43-
Base.parent(A::InvWarpedView) = parent(A.inner)
50+
@inline Base.parent(A::InvWarpedView) = parent(A.inner)
4451
@inline Base.axes(A::InvWarpedView) = axes(A.inner)
52+
@inline Base.size(A::InvWarpedView) = size(A.inner)
4553

46-
IndexStyle(::Type{T}) where {T<:InvWarpedView} = IndexCartesian()
47-
@inline Base.getindex(A::InvWarpedView{T,N}, I::Vararg{Int,N}) where {T,N} = A.inner[I...]
48-
49-
Base.size(A::InvWarpedView) = size(A.inner)
50-
Base.size(A::InvWarpedView, d) = size(A.inner, d)
54+
Base.@propagate_inbounds Base.getindex(A::InvWarpedView{T,N}, I::Vararg{Int,N}) where {T,N} = A.inner[I...]
5155

5256
function Base.showarg(io::IO, A::InvWarpedView, toplevel)
5357
print(io, "InvWarpedView(")
@@ -60,37 +64,3 @@ function Base.showarg(io::IO, A::InvWarpedView, toplevel)
6064
print(io, ')')
6165
end
6266
end
63-
64-
"""
65-
invwarpedview(img, tinv, [indices]; kwargs...) -> wv
66-
67-
Create a view of `img` that lazily transforms any given index `I`
68-
passed to `wv[I]` so that `wv[I] == img[inv(tinv)(I)]`.
69-
70-
Except for the lazy evaluation, the following two lines are equivalent:
71-
72-
```julia
73-
warp(img, inv(tform), [indices]; kwargs...)
74-
invwarpedview(img, tform, [indices]; kwargs...)
75-
```
76-
77-
For detailed explaination of warp, associated arguments and parameters,
78-
please refer to [`warp`](@ref).
79-
"""
80-
function invwarpedview(A::AbstractArray, tinv::Transformation, indices::Tuple=autorange(A, tinv); kwargs...)
81-
InvWarpedView(box_extrapolation(A; kwargs...), tinv, indices)
82-
end
83-
84-
# For SubArray:
85-
# 1. We can exceed the boundary of SubArray by using its parent and thus trick Interpolations in
86-
# order to get better extrapolation result around the border. Otherwise it will just fill it.
87-
# 2. For default indices, we use `IdentityUnitRange`, which guarantees `r[i] == i`, to preserve the view indices.
88-
function invwarpedview(A::SubArray, tinv::Transformation; kwargs...)
89-
default_indices = map(IdentityUnitRange, autorange(CartesianIndices(A.indices), tinv))
90-
invwarpedview(A, tinv, default_indices; kwargs...)
91-
end
92-
function invwarpedview(A::SubArray, tinv::Transformation, indices::Tuple; kwargs...)
93-
inner = parent(A)
94-
new_inner = InvWarpedView(inner, tinv, autorange(inner, tinv))
95-
view(new_inner, indices...)
96-
end

src/warp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ There're some high-level interfaces of `warp`:
3939
- image rotation: [`imrotate`](@ref)
4040
- image resize: [`imresize`](@ref)
4141
42-
There are also lazy version of `warp`:
42+
There are also lazy versions of `warp`:
4343
4444
- [`WarpedView`](@ref) is almost equivalent to `warp` except that it does not allocate memory.
45-
- [`invwarpedview(img, tform, [indices]; kwargs...)`](@ref ImageTransformations.invwarpedview)
45+
- [`InvWarpedView(img, tform, [indices]; kwargs...)`](@ref ImageTransformations.InvWarpedView)
4646
is almost equivalent to `warp(img, inv(tform), [indices]; kwargs...)` except that it does not
4747
allocate memory.
4848

src/warpedview.jl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@ function WarpedView(
2222
WarpedView{T,N,typeof(A),typeof(tform),typeof(inds),typeof(etp)}(A, tform, inds, etp)
2323
end
2424

25-
Base.parent(A::WarpedView) = A.parent
25+
@inline Base.parent(A::WarpedView) = A.parent
2626
@inline Base.axes(A::WarpedView) = A.indices
27+
@inline Base.size(A::WarpedView) = map(length,axes(A))
2728

28-
IndexStyle(::Type{T}) where {T<:WarpedView} = IndexCartesian()
29-
@inline Base.getindex(A::WarpedView{T,N}, I::Vararg{Int,N}) where {T,N} =
30-
T(_getindex(A.extrapolation, A.transform(SVector(I))))
31-
Base.size(A::WarpedView{T,N,TA,F}) where {T,N,TA,F} = map(length,axes(A))
32-
Base.size(A::WarpedView{T,N,TA,F}, d) where {T,N,TA,F} = length(axes(A,d))
33-
34-
Base.size(A::WarpedView{T,N,TA,F,NTuple{N,Base.OneTo{Int}}}) where {T,N,TA,F} = map(length, A.indices)
35-
Base.size(A::WarpedView{T,N,TA,F,NTuple{N,Base.OneTo{Int}}}, d) where {T,N,TA,F} = d <= N ? length(A.indices[d]) : 1
29+
Base.@propagate_inbounds function Base.getindex(A::WarpedView{T,N}, I::Vararg{Int,N}) where {T,N}
30+
convert(T, _getindex(A.extrapolation, A.transform(SVector(I))))
31+
end
3632

3733
function Base.showarg(io::IO, A::WarpedView, toplevel)
3834
print(io, "WarpedView(")

test/deprecated.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,22 @@ using ImageTransformations: box_extrapolation
8585
@test nearlysame(invwarpedview(img, tfm, 1), InvWarpedView(box_extrapolation(img; fillvalue=1), tfm))
8686
@test nearlysame(invwarpedview(img, tfm, Periodic()), InvWarpedView(box_extrapolation(img; fillvalue=Periodic()), tfm))
8787

88+
@test nearlysame(InvWarpedView(img, tfm, Constant()), InvWarpedView(img, tfm; method=Constant()))
89+
@test nearlysame(InvWarpedView(img, tfm, Constant(), 1), InvWarpedView(img, tfm; method=Constant(), fillvalue=1))
90+
@test nearlysame(InvWarpedView(img, tfm, 1, Constant()), InvWarpedView(img, tfm; method=Constant(), fillvalue=1))
91+
@test nearlysame(InvWarpedView(img, tfm, 1), InvWarpedView(img, tfm; fillvalue=1))
92+
@test nearlysame(InvWarpedView(img, tfm, Periodic()), InvWarpedView(img, tfm; fillvalue=Periodic()))
93+
8894
@test nearlysame(invwarpedview(img, tfm, axes(img), Constant()), InvWarpedView(box_extrapolation(img; method=Constant()), tfm, axes(img)))
8995
@test nearlysame(invwarpedview(img, tfm, axes(img), Constant(), 1), InvWarpedView(box_extrapolation(img; method=Constant(), fillvalue=1), tfm, axes(img)))
9096
@test nearlysame(invwarpedview(img, tfm, axes(img), 1, Constant()), InvWarpedView(box_extrapolation(img; method=Constant(), fillvalue=1), tfm, axes(img)))
9197
@test nearlysame(invwarpedview(img, tfm, axes(img), 1), InvWarpedView(box_extrapolation(img; fillvalue=1), tfm, axes(img)))
9298
@test nearlysame(invwarpedview(img, tfm, axes(img), Periodic()), InvWarpedView(box_extrapolation(img; fillvalue=Periodic()), tfm, axes(img)))
99+
100+
@test nearlysame(InvWarpedView(img, tfm, axes(img), Constant()), InvWarpedView(img, tfm, axes(img); method=Constant()))
101+
@test nearlysame(InvWarpedView(img, tfm, axes(img), Constant(), 1), InvWarpedView(img, tfm, axes(img); method=Constant(), fillvalue=1))
102+
@test nearlysame(InvWarpedView(img, tfm, axes(img), 1, Constant()), InvWarpedView(img, tfm, axes(img); method=Constant(), fillvalue=1))
103+
@test nearlysame(InvWarpedView(img, tfm, axes(img), 1), InvWarpedView(img, tfm, axes(img); fillvalue=1))
104+
@test nearlysame(InvWarpedView(img, tfm, axes(img), Periodic()), InvWarpedView(img, tfm, axes(img); fillvalue=Periodic()))
93105
end
94106
end

0 commit comments

Comments
 (0)