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

Support arbitrary indices #18

Merged
merged 2 commits into from
Apr 11, 2017
Merged

Support arbitrary indices #18

merged 2 commits into from
Apr 11, 2017

Conversation

timholy
Copy link
Member

@timholy timholy commented Apr 11, 2017

This leverages recent changes in Interpolations (JuliaMath/Interpolations.jl#146) to provide support for arbitrary indices in warping. It also rewrites restrict to support arbitrary indices. Note that this very similar to #12, but by keeping any branches out of the innermost loop and by circumventing JuliaLang/julia#9080, I've been able to keep the performance essentially unchanged (less than 10% difference).

@codecov-io
Copy link

codecov-io commented Apr 11, 2017

Codecov Report

Merging #18 into master will increase coverage by 0.41%.
The diff coverage is 97.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #18      +/-   ##
==========================================
+ Coverage   91.25%   91.66%   +0.41%     
==========================================
  Files           4        4              
  Lines         160      180      +20     
==========================================
+ Hits          146      165      +19     
- Misses         14       15       +1
Impacted Files Coverage Δ
src/ImageTransformations.jl 100% <ø> (ø) ⬆️
src/warp.jl 88.46% <83.33%> (-1.54%) ⬇️
src/resizing.jl 93.54% <98.75%> (+0.82%) ⬆️

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 24912f9...43597d8. Read the comment docs.

@timholy
Copy link
Member Author

timholy commented Apr 11, 2017

0.6 failure needs fixing in Rotations, presumably.

@@ -36,5 +36,25 @@ tfm = recenter(RotMatrix(-pi/4), center(img_pyramid))
imgr = warp(img_pyramid, tfm)
@test indices(imgr) == (0:6, 0:6)

# I do this very complicated because turns out NaNs are hard to compare...
# Use map and === because of the NaNs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

src/resizing.jl Outdated
restrict!(out, A, dim)
out
end

# out should have efficient linear indexing
@generated function restrict!{T,N}(out::AbstractArray{T,N}, A::AbstractArray, dim)
function restrict!{T,N}(out::AbstractArray{T,N}, A::AbstractArray, dim)
if dim > N
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we throw an error in such a case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to doing so, but I was mimicking this:

julia> a = 1:3
1:3

julia> sum(a, 1)
1-element Array{Int64,1}:
 6

julia> sum(a, 2)
3-element Array{Int64,1}:
 1
 2
 3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I think consistency with Base is the cleanest way, yes

stride_1 = 1
@nexprs $N d->(stride_{d+1} = stride_d*size(out,d))
@nexprs $N d->offset_d = 0
z = convert(T, zero(first(A)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not z = zero(T) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not certain, but I think I put it this way originally to support the following:

julia> a = [rand(3) for i = 1:5]
5-element Array{Array{Float64,1},1}:                                                                                                                                                         
 [0.465388,0.525425,0.753336]                                                                                                                                                                
 [0.890223,0.465896,0.191895]                                                                                                                                                                
 [0.205448,0.896783,0.0923702]                                                                                                                                                               
 [0.538556,0.862554,0.581898]                                                                                                                                                                
 [0.731725,0.887581,0.0116221]

julia> restrict(a, 1)
3-element Array{Array{Float64,1},1}:                                                                                                                                                         
 [0.45525,0.379187,0.424642]                                                                                                                                                                 
 [0.459918,0.780504,0.239633]                                                                                                                                                                
 [0.500502,0.659429,0.151285]

Clearly I should add that to the tests.

test/resizing.jl Outdated
@@ -30,6 +30,10 @@
img1 = colorview(RGB, fill(0.9, 3, 5, 5))
img2 = colorview(RGB, fill(N0f8(0.9), 3, 5, 5))
@test isapprox(channelview(restrict(img1)), channelview(restrict(img2)), rtol=0.01)
# Non-1 indices
@test parent(restrict(OffsetArray(A, (-2,1,0)), 1)) == restrict(A, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you consider:

@test parent(@inferred(restrict(OffsetArray(A, (-2,1,0)), 1))) == restrict(A, 1)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, there was a type instability due to this method, since A can change its type. Thanks for the suggestion!

@Evizero
Copy link
Member

Evizero commented Apr 11, 2017

Very cool! Made some comments here and there when something caught my eye

@timholy
Copy link
Member Author

timholy commented Apr 11, 2017

Thanks for the review, @Evizero!

This uses generated functions for looping instead of CartesianRange
because of julia issue 9080.
@timholy timholy merged commit 5cafc12 into master Apr 11, 2017
@timholy timholy deleted the teh/non1 branch April 11, 2017 15:50
@Evizero
Copy link
Member

Evizero commented Apr 11, 2017

Worth a tag? I am eyeing the merge of JuliaImages/ImageInTerminal.jl#9

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.

3 participants