Skip to content

Commit 289f7ea

Browse files
committed
updates for Julia v0.7
1 parent 93efe78 commit 289f7ea

File tree

13 files changed

+153
-144
lines changed

13 files changed

+153
-144
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.6
1+
julia 0.7-beta
22
ImageCore 0.1.2
33
CoordinateTransformations 0.4.0
44
Interpolations 0.4

src/ImageTransformations.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ using Interpolations, AxisAlgorithms
99
using OffsetArrays
1010
using FixedPointNumbers
1111
using ColorTypes, Colors, ColorVectorSpace
12-
using Compat
1312
using IdentityRanges
1413

15-
import Base: start, next, done, eltype, iteratorsize, size, length
16-
using Base: tail, Cartesian, Indices
14+
import Base: start, next, done, eltype, size, length
15+
using Base: tail, Indices
16+
using Base.Cartesian
1717
using ColorTypes: AbstractGray, TransparentGray, TransparentRGB
1818

1919
export
@@ -36,7 +36,7 @@ include("invwarpedview.jl")
3636

3737
@inline _getindex(A, v::StaticVector) = A[convert(Tuple, v)...]
3838

39-
center(img::AbstractArray{T,N}) where {T,N} = SVector{N}(map(_center, indices(img)))
39+
center(img::AbstractArray{T,N}) where {T,N} = SVector{N}(map(_center, axes(img)))
4040
_center(ind::AbstractUnitRange) = (first(ind)+last(ind))/2
4141

4242
end # module

src/autorange.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function autorange(img, tform)
2-
R = CartesianRange(indices(img))
2+
R = CartesianIndices(axes(img))
33
autorange(R, tform)
44
end
55

6-
function autorange(R::CartesianRange, tform)
6+
function autorange(R::CartesianIndices, tform)
77
mn = mx = tform(SVector(first(R).I))
88
for I in CornerIterator(R)
99
x = tform(SVector(I.I))
@@ -22,13 +22,13 @@ struct CornerIterator{I<:CartesianIndex}
2222
start::I
2323
stop::I
2424
end
25-
CornerIterator(R::CartesianRange) = CornerIterator(first(R), last(R))
25+
CornerIterator(R::CartesianIndices) = CornerIterator(first(R), last(R))
2626

2727
eltype(::Type{CornerIterator{I}}) where {I} = I
28-
iteratorsize(::Type{CornerIterator{I}}) where {I} = Base.HasShape()
28+
Base.Iterators.IteratorSize(::Type{CornerIterator{I}}) where {I<:CartesianIndex{N}} where {N} = Base.Iterators.HasShape{N}()
2929

3030
# in 0.6 we could write: 1 .+ (iter.stop.I .- iter.start.I .!= 0)
31-
size(iter::CornerIterator{CartesianIndex{N}}) where {N} = ntuple(d->iter.stop.I[d]-iter.start.I[d]==0 ? 1 : 2, Val{N})::NTuple{N,Int}
31+
size(iter::CornerIterator{CartesianIndex{N}}) where {N} = ntuple(d->iter.stop.I[d]-iter.start.I[d]==0 ? 1 : 2, Val(N))::NTuple{N,Int}
3232
length(iter::CornerIterator) = prod(size(iter))
3333

3434
@inline function start(iter::CornerIterator{I}) where I<:CartesianIndex

src/interpolations.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ end
5151
# This is type-piracy, but necessary if we want Interpolations to be
5252
# independent of OffsetArrays.
5353
function AxisAlgorithms.A_ldiv_B_md!(dest::OffsetArray, F, src::OffsetArray, dim::Integer, b::AbstractVector)
54-
indsdim = indices(parent(src), dim)
55-
indsF = indices(F)[2]
54+
indsdim = axes(parent(src), dim)
55+
indsF = axes(F)[2]
5656
if indsF == indsdim
5757
AxisAlgorithms.A_ldiv_B_md!(parent(dest), F, parent(src), dim, b)
5858
return dest
5959
end
60-
throw(DimensionMismatch("indices $(indices(parent(src))) do not match $(indices(F))"))
60+
throw(DimensionMismatch("indices $(axes(parent(src))) do not match $(axes(F))"))
6161
end

src/invwarpedview.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ function InvWarpedView(inner::InvWarpedView, outer_tinv::Transformation, inds::T
4646
end
4747

4848
Base.parent(A::InvWarpedView) = parent(A.inner)
49-
@inline Base.indices(A::InvWarpedView) = indices(A.inner)
49+
@inline Base.axes(A::InvWarpedView) = axes(A.inner)
5050

51-
Compat.IndexStyle(::Type{T}) where {T<:InvWarpedView} = IndexCartesian()
51+
IndexStyle(::Type{T}) where {T<:InvWarpedView} = IndexCartesian()
5252
@inline Base.getindex(A::InvWarpedView{T,N}, I::Vararg{Int,N}) where {T,N} = A.inner[I...]
5353

5454
Base.size(A::InvWarpedView) = size(A.inner)
@@ -67,9 +67,9 @@ function ShowItLikeYouBuildIt.showarg(io::IO, A::SubArray{T,N,W}) where {T<:Numb
6767
print(io, "view(")
6868
showarg(io, parent(A))
6969
print(io, ", ")
70-
for (i, el) in enumerate(A.indexes)
70+
for (i, el) in enumerate(A.indices)
7171
print(io, el)
72-
i < length(A.indexes) && print(io, ", ")
72+
i < length(A.indices) && print(io, ", ")
7373
end
7474
print(io, ')')
7575
end
@@ -141,7 +141,7 @@ function invwarpedview(
141141
tinv::Transformation) where {T,N,W<:InvWarpedView,I<:Tuple{Vararg{AbstractUnitRange}}}
142142
inner = parent(inner_view)
143143
new_inner = InvWarpedView(inner, tinv, autorange(inner, tinv))
144-
inds = autorange(CartesianRange(inner_view.indexes), tinv)
144+
inds = autorange(CartesianIndices(inner_view.indices), tinv)
145145
view(new_inner, map(IdentityRange, inds)...)
146146
end
147147

src/resizing.jl

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ See also [`imresize`](@ref).
1010
"""
1111
restrict(img::AbstractArray, ::Tuple{}) = img
1212

13-
restrict(A::AbstractArray, region::Vector{Int}) = restrict(A, (region...))
13+
restrict(A::AbstractArray, region::Vector{Int}) = restrict(A, (region...,))
1414
restrict(A::AbstractArray) = restrict(A, coords_spatial(A))
1515
function restrict(A::AbstractArray, region::Dims)
1616
restrict(restrict(A, region[1]), Base.tail(region))
1717
end
1818

1919
function restrict(A::AbstractArray{T,N}, dim::Integer) where {T,N}
20-
indsA = indices(A)
21-
newinds = ntuple(i->i==dim?restrict_indices(indsA[dim]):indsA[i], Val{N})
20+
indsA = axes(A)
21+
newinds = ntuple(i->i==dim ? restrict_indices(indsA[dim]) : indsA[i], Val(N))
2222
out = similar(Array{restrict_eltype(first(A)),N}, newinds)
2323
restrict!(out, A, dim)
2424
out
@@ -35,9 +35,9 @@ restrict_eltype(x::Colorant) = restrict_eltype_default(convert(ARGB, x))
3535

3636
function restrict!(out::AbstractArray{T,N}, A::AbstractArray, dim) where {T,N}
3737
if dim > N
38-
return copy!(out, A)
38+
return copyto!(out, A)
3939
end
40-
indsout, indsA = indices(out), indices(A)
40+
indsout, indsA = axes(out), axes(A)
4141
ndims(out) == ndims(A) || throw(DimensionMismatch("input and output must have the same number of dimensions"))
4242
for d = 1:length(indsA)
4343
target = d==dim ? restrict_indices(indsA[d]) : indsA[d]
@@ -155,7 +155,12 @@ end
155155
end
156156

157157
restrict_size(len::Integer) = isodd(len) ? (len+1)>>1 : (len>>1)+1
158-
158+
# CHECKME: wild guess here
159+
function restrict_indices(r::Base.Slice)
160+
f, l = first(r), last(r)
161+
isodd(f) && return (f+1)>>1:restrict_size(l)
162+
f>>1 : (isodd(l) ? (l+1)>>1 : l>>1)
163+
end
159164
restrict_indices(r::Base.OneTo) = Base.OneTo(restrict_size(length(r)))
160165
function restrict_indices(r::UnitRange)
161166
f, l = first(r), last(r)
@@ -173,8 +178,8 @@ function imresize(original::AbstractArray, short_size::Tuple)
173178
imresize(original, new_size)
174179
end
175180
odims(original, i, short_size::Tuple{Integer,Vararg{Integer}}) = size(original, i)
176-
odims(original, i, short_size::Tuple{}) = indices(original, i)
177-
odims(original, i, short_size) = oftype(first(short_size), indices(original, i))
181+
odims(original, i, short_size::Tuple{}) = axes(original, i)
182+
odims(original, i, short_size) = oftype(first(short_size), axes(original, i))
178183

179184
"""
180185
imresize(img, sz) -> imgr
@@ -193,18 +198,18 @@ See also [`restrict`](@ref).
193198
"""
194199
function imresize(original::AbstractArray{T,0}, new_inds::Tuple{}) where T
195200
Tnew = imresize_type(first(original))
196-
copy!(similar(original, Tnew), original)
201+
copyto!(similar(original, Tnew), original)
197202
end
198203

199204
function imresize(original::AbstractArray{T,N}, new_size::Dims{N}) where {T,N}
200205
Tnew = imresize_type(first(original))
201-
inds = indices(original)
206+
inds = axes(original)
202207
if map(length, inds) == new_size
203208
dest = similar(original, Tnew, new_size)
204-
if indices(dest) == inds
205-
copy!(dest, original)
209+
if axes(dest) == inds
210+
copyto!(dest, original)
206211
else
207-
copy!(dest, CartesianRange(indices(dest)), original, CartesianRange(inds))
212+
copyto!(dest, CartesianIndices(axes(dest)), original, CartesianIndices(inds))
208213
end
209214
else
210215
imresize!(similar(original, Tnew, new_size), original)
@@ -213,8 +218,8 @@ end
213218

214219
function imresize(original::AbstractArray{T,N}, new_inds::Indices{N}) where {T,N}
215220
Tnew = imresize_type(first(original))
216-
if indices(original) == new_inds
217-
copy!(similar(original, Tnew), original)
221+
if axes(original) == new_inds
222+
copyto!(similar(original, Tnew), original)
218223
else
219224
imresize!(similar(original, Tnew, new_inds), original)
220225
end
@@ -247,8 +252,10 @@ function imresize!(resized::AbstractArray{T,N}, original::AbstractInterpolation{
247252
# (0.5, 0.5) -> (0.5, 0.5) (outer corner, top left)
248253
# size(resized)+0.5 -> size(original)+0.5 (outer corner, lower right)
249254
# This ensures that both images cover exactly the same area.
250-
Ro, Rr = CartesianRange(indices(original)), CartesianRange(indices(resized))
251-
sf = map(/, (last(Ro)-first(Ro)+1).I, (last(Rr)-first(Rr)+1).I) # +1 for outer corners
255+
Ro, Rr = CartesianIndices(axes(original)), CartesianIndices(axes(resized))
256+
# CHECKME: is this general enough? previously had
257+
# sf = map(/, (last(Ro)-first(Ro)+1).I, (last(Rr)-first(Rr)+1).I) # +1 for outer corners
258+
sf = map(/, (last(Ro)-first(Ro)).I .+ 1, (last(Rr)-first(Rr)).I .+ 1) # +1 for outer corners
252259
offset = map((io,ir,s)->io - 0.5 - s*(ir-0.5), first(Ro).I, first(Rr).I, sf)
253260
if all(x->x >= 1, sf)
254261
@inbounds for I in Rr
@@ -268,6 +275,6 @@ end
268275
@inline map3(f, a, b, c) = (f(a[1], b[1], c[1]), map3(f, tail(a), tail(b), tail(c))...)
269276
@inline map3(f, ::Tuple{}, ::Tuple{}, ::Tuple{}) = ()
270277

271-
@compat function clampR(I::NTuple{N}, R::CartesianRange{N}) where N
278+
function clampR(I::NTuple{N}, R::CartesianIndices{N}) where N
272279
map3(clamp, I, first(R).I, last(R).I)
273280
end

src/warp.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ julia> using Images, CoordinateTransformations, TestImages, OffsetArrays
5050
5151
julia> img = testimage("lighthouse");
5252
53-
julia> indices(img)
53+
julia> axes(img)
5454
(Base.OneTo(512),Base.OneTo(768))
5555
5656
# Rotate around the center of `img`
@@ -59,7 +59,7 @@ AffineMap([0.707107 0.707107; -0.707107 0.707107], [-196.755,293.99])
5959
6060
julia> imgw = warp(img, tfm);
6161
62-
julia> indices(imgw)
62+
julia> axes(imgw)
6363
(-196:709,-68:837)
6464
6565
# Alternatively, specify the origin in the image itself
@@ -70,12 +70,12 @@ LinearMap([0.707107 -0.707107; 0.707107 0.707107])
7070
7171
julia> imgw = warp(img0, rot);
7272
73-
julia> indices(imgw)
73+
julia> axes(imgw)
7474
(-293:612,-293:611)
7575
7676
julia> imgr = parent(imgw);
7777
78-
julia> indices(imgr)
78+
julia> axes(imgr)
7979
(Base.OneTo(906),Base.OneTo(905))
8080
```
8181
"""
@@ -85,7 +85,7 @@ function warp(img::AbstractExtrapolation{T}, tform, inds::Tuple = autorange(img,
8585
end
8686

8787
function warp!(out, img::AbstractExtrapolation, tform)
88-
@inbounds for I in CartesianRange(indices(out))
88+
@inbounds for I in CartesianIndices(axes(out))
8989
out[I] = _getindex(img, tform(SVector(I.I)))
9090
end
9191
out

src/warpedview.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ function WarpedView(
3838
end
3939

4040
Base.parent(A::WarpedView) = A.parent
41-
@inline Base.indices(A::WarpedView) = A.indices
41+
@inline Base.axes(A::WarpedView) = A.indices
4242

43-
Compat.IndexStyle(::Type{T}) where {T<:WarpedView} = IndexCartesian()
43+
IndexStyle(::Type{T}) where {T<:WarpedView} = IndexCartesian()
4444
@inline Base.getindex(A::WarpedView{T,N}, I::Vararg{Int,N}) where {T,N} =
4545
T(_getindex(A.extrapolation, A.transform(SVector(I))))
4646

47-
Base.size(A::WarpedView{T,N,TA,F}) where {T,N,TA,F} = OffsetArrays.errmsg(A)
48-
Base.size(A::WarpedView{T,N,TA,F}, d) where {T,N,TA,F} = OffsetArrays.errmsg(A)
47+
Base.size(A::WarpedView{T,N,TA,F}) where {T,N,TA,F} = size(parent(A))
48+
Base.size(A::WarpedView{T,N,TA,F}, d) where {T,N,TA,F} = size(parent(A),d)
4949

5050
Base.size(A::WarpedView{T,N,TA,F,NTuple{N,Base.OneTo{Int}}}) where {T,N,TA,F} = map(length, A.indices)
5151
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

test/autorange.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
# (i.e. without any singleton array dimension of size 1)
77
si(num::Number) = 1
88
ei(num::Number) = num
9-
si(num::Range) = minimum(num)
10-
ei(num::Range) = maximum(num)
9+
si(num::AbstractRange) = minimum(num)
10+
ei(num::AbstractRange) = maximum(num)
1111
for t in ((2,), (2,3), (2,3,4), (2,3,4,5), # OneTo
1212
(-1:2,), (-1:2,-2:3), (-1:2,-2:3,-3:4)) # Non OneTo
1313
N = length(t)
1414
@testset "$N-d array without singleton dimension" begin
15-
cr = CartesianRange(t)
15+
cr = CartesianIndices(t)
1616
ci = @inferred(ImageTransformations.CornerIterator(cr))
1717
@test typeof(ci) <: ImageTransformations.CornerIterator{CartesianIndex{N}}
1818
@test ci.start === first(cr)
@@ -55,7 +55,7 @@
5555
@testset "0-element and 1-element edge cases" begin
5656
for t in ((),(1,),(1,1),(1,1,1))
5757
N = length(t)
58-
cr = CartesianRange(t)
58+
cr = CartesianIndices(t)
5959
ci = @inferred(ImageTransformations.CornerIterator(cr))
6060
@test ci.start === first(cr)
6161
@test ci.stop === last(cr)
@@ -69,7 +69,7 @@
6969
end
7070

7171
@testset "arrays with singleton dimensions" begin
72-
cr = CartesianRange((1,3))
72+
cr = CartesianIndices((1,3))
7373
ci = @inferred(ImageTransformations.CornerIterator(cr))
7474
@test ci.start === first(cr)
7575
@test ci.stop === last(cr)
@@ -81,7 +81,7 @@
8181
CartesianIndex{2}((1,1)) CartesianIndex{2}((1,3))
8282
]
8383
# two singleton dimensions
84-
cr = CartesianRange((1,3,1,3))
84+
cr = CartesianIndices((1,3,1,3))
8585
ci = @inferred(ImageTransformations.CornerIterator(cr))
8686
@test ci.start === first(cr)
8787
@test ci.stop === last(cr)
@@ -127,8 +127,8 @@ end
127127
end
128128
end
129129
#should also work with non-static transforms (Github #48)
130-
tfm = LinearMap(eye(2))
131-
tfm_s = LinearMap(SMatrix{2,2}(eye(2)))
130+
tfm = LinearMap(Matrix(1.0*I,2,2))
131+
tfm_s = LinearMap(SMatrix{2,2}(Matrix(1.0*I,2,2)))
132132
tst_img = zeros(5,5)
133133
rnge = ImageTransformations.autorange(tst_img, tfm_s)
134134
@test rnge == ImageTransformations.autorange(tst_img, tfm)

0 commit comments

Comments
 (0)