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

type inference fails with more than 13 arguments #26092

Closed
Alexander-Barth opened this issue Feb 17, 2018 · 1 comment
Closed

type inference fails with more than 13 arguments #26092

Alexander-Barth opened this issue Feb 17, 2018 · 1 comment

Comments

@Alexander-Barth
Copy link

The following function is type-unstable. However, if I just remove one of the parameters (positional or keyword), then the function becomes type stable. Is there a limit about the number of arguments ? 13 arguments are fine for type inference but not 14 or more.

function myfun(x,v::Vector{T},distbin,mincount;
               len::T = 1.,
               var0::T = 1.,
               minlen::T = 1e-5,
               maxlen::T = 10.,
               minvar0::T = 0.,
               maxvar0::T = 10.,
               tolrel::T = 1e-4,
               maxpoints::Int = 1000000,
               nmean::Int = 1,
               stdcovar::T = 1.
               ) where T

    pmax = length(distbin)
    distx = zeros(T,pmax)
    for i = 1:pmax
        distx[i] = distbin[i]
    end
    return distx
end
code_warntype myfun(1.,[1.],1:10,100)

produces:

Variables:
  #self#::#myfun
  x::Float64
  v::Array{Float64,1}
  distbin::UnitRange{Int64}
  mincount::Int64

Body:
  begin 
      return $(Expr(:invoke, MethodInstance for #myfun#6(::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Int64, ::Int64, ::Float64, ::#myfun, ::Float64, ::Array{Float64,1}, ::UnitRange{Int64}, ::Int64), :(Main.#myfun#6), 1.0, 1.0, 1.0e-5, 10.0, 0.0, 10.0, 0.0001, 1000000, 1, 1.0, :(#self#), :(x), :(v), :(distbin), :(mincount)))
  end::Any

If I specify the type of distbin (for example UnitRange{Int64}), then type inference also works again.
It seems to me that there is some internal limit for the function specialization and type inference.

Is this documented some where?
I see this behaviour on julia 0.6.2 and 0.6.1.

Julia Version 0.6.2
Commit d386e40c17 (2017-12-13 18:08 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i3-3120M CPU @ 2.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)
@yuyichao
Copy link
Contributor

Dup of #22255

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

2 participants