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

Insufficient method specialization for parametric stagedfunction #8944

Closed
timholy opened this issue Nov 8, 2014 · 0 comments
Closed

Insufficient method specialization for parametric stagedfunction #8944

timholy opened this issue Nov 8, 2014 · 0 comments

Comments

@timholy
Copy link
Sponsor Member

timholy commented Nov 8, 2014

In #8504 (comment), I forced method specialization by adding parameters. However, hydra-like, this has caused a new problem: suddenly, the method is no longer being adequately specialized on its splatted inputs.

module AVDebug

type View{T,N,P<:AbstractArray,I<:(RangeIndex...)} <: AbstractArray{T,N}
    parent::P
    indexes::I
    dims::NTuple{N,Int}
end

stagedfunction subview{T,NP}(A::AbstractArray{T,NP}, I::RangeIndex...)
# stagedfunction subview(A::AbstractArray, I::RangeIndex...)
#     T = eltype(A)
    @show I
    N = length(I)
    sizeexprs = [:(length(I[$k])) for k = 1:length(I)]
    It = ntuple(length(I), i->UnitRange{Int})
    Iexprs = [I[k] <: Real ? (:(I[$k]:I[$k])) : (:(I[$k])) for k = 1:length(I)]
    dims = :(tuple($(sizeexprs...)))
    Iext = :(tuple($(Iexprs...)))
    :(View{$T,$N,$A,$It}(A, $Iext, $dims))
end

end

Test file:

import AVDebug

A = reshape(float64(1:300), 5, 5, 3, 4)
S = AVDebug.subview(A, 1:2, 1:2, 1:2, 1:2)
@show typeof(S)
S = AVDebug.subview(A, 1:2, 1:2, 1:2, 2)
@show typeof(S)
S = AVDebug.subview(A, 1:2, 1:2, 2, 1:2)
@show typeof(S)

Output:

julia> include("AVtest.jl")
I = (UnitRange{Int64},UnitRange{Int64},UnitRange{Int64},UnitRange{Int64})
typeof(S) = View{Float64,4,Array{Float64,4},(UnitRange{Int64},UnitRange{Int64},UnitRange{Int64},UnitRange{Int64})}
I = (UnitRange{Int64},UnitRange{Int64},UnitRange{Int64},Int64)
typeof(S) = View{Float64,4,Array{Float64,4},(UnitRange{Int64},UnitRange{Int64},UnitRange{Int64},UnitRange{Int64})}
ERROR: step cannot be zero
 in call at ./range.jl:42
 in - at operators.jl:327
 in colon at range.jl:75
 in anonymous at no file
 in include at ./boot.jl:242
 in include_from_node1 at ./loading.jl:128
while loading /tmp/AVtest.jl, in expression starting on line 8

You can see it never gets into the body of the function.

If I switch to the other function signature (see the commented-out lines), then this test passes (but of course then it starts failing #8504).

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

No branches or pull requests

1 participant