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

Make parametric stagedfunctions work better #8505

Closed
timholy opened this issue Sep 28, 2014 · 4 comments
Closed

Make parametric stagedfunctions work better #8505

timholy opened this issue Sep 28, 2014 · 4 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@timholy
Copy link
Member

timholy commented Sep 28, 2014

h gives what one wants, but it's not as pretty as it should be.

stagedfunction f{T<:FloatingPoint}(a::Vector{T})
    @show a
    :(println($T))
end

stagedfunction g(a::Vector)
    T = eltype(a)
    @show a
    :(println($T))
end

stagedfunction h{T<:FloatingPoint}(a::Vector{T})
    TT = eltype(a)
    @show a
    :(println($TT))
end

Test:

julia> include("/tmp/params.jl")
h (generic function with 1 method)

julia> af = [1.0,2.0]
2-element Array{Float64,1}:
 1.0
 2.0

julia> ai = [1,2]
2-element Array{Int64,1}:
 1
 2

julia> f(af)
a = Array{Float64,1}
ERROR: T not defined
 in f at /tmp/params.jl:3

julia> g(af)
a = Array{Float64,1}
Float64

julia> h(af)
a = Array{Float64,1}
Float64

julia> f(ai)
ERROR: `f` has no method matching f(::Array{Int64,1})

julia> g(ai)
a = Array{Int64,1}
Int64

julia> h(ai)
ERROR: `h` has no method matching h(::Array{Int64,1})
@timholy
Copy link
Member Author

timholy commented Sep 28, 2014

Unfortunately, on #8501 I used up a little more time than I actually had available to work on julia-core projects, so I'm not going to get to these for a little while.

@JeffBezanson JeffBezanson added the bug Indicates an unexpected problem or unintended behavior label Oct 23, 2014
@JeffBezanson JeffBezanson self-assigned this Oct 23, 2014
@JeffBezanson JeffBezanson added this to the 0.4 milestone Oct 23, 2014
@Jutho
Copy link
Contributor

Jutho commented Oct 25, 2014

Thanks for this, however, I noticed a bug if the parameters in the function specification does not match the order in which they appear in the arguments. That is:

stagedfunction foo1{N,T}(a::Array{T,N})
    println("N = $N, T = $T")
    return :a
end

stagedfunction foo2{T,N}(a::Array{T,N})
    println("N = $N, T = $T")
    return :a
end

foo1(randn(3,3));  # => N = Float64, T = 2
foo2(randn(3,3)); #=> N = 2, T = Float64

@Jutho
Copy link
Contributor

Jutho commented Oct 27, 2014

Thanks for fixing this

@timholy
Copy link
Member Author

timholy commented Oct 27, 2014

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants