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

std() type instability? #21811

Closed
alyst opened this issue May 11, 2017 · 5 comments
Closed

std() type instability? #21811

alyst opened this issue May 11, 2017 · 5 comments

Comments

@alyst
Copy link
Contributor

alyst commented May 11, 2017

Julia 0.5.2

julia> @code_warntype std(randn(5))
Variables:
  #self#::Base.#std
  A::Array{Float64,1}

Body:
  begin 
      return (Base.sqrt)($(Expr(:invoke, LambdaInfo for (::Base.#kw##var)(::Array{Any,1}, ::Base.#var, ::Array{Float64,1}), Base.#var, :($(Expr(:invoke, LambdaInfo for vector_any(::Any, ::Vararg{Any,N}), :(Base.vector_any), :(:corrected), true, :(:mean), :(Base.nothing)))), :(Base.var), :(A))))::Any
  end::Any

Julia 0.6rc-1

julia> @code_warntype std(randn(5))
Variables:
  #self#::Base.#std
  A::Array{Float64,1}

Body:
  begin 
      return (Base.sqrt)($(Expr(:invoke, MethodInstance for (::Base.#kw##var)(::Array{Any,1}, ::Base.#var, ::Array{Float64,1}), :($(QuoteNode(Base.#var))), :($(Expr(:invoke, MethodInstance for vector_any(::Any, ::Vararg{Any,N} where N), :(Base.vector_any), :(:corrected), true, :(:mean), :(Base.nothing)))), :(Base.var), :(A))))::Any
  end::Any

The 1st problem is type instability.

The 2nd problem is that for functions taking keyword arguments I cannot get the meaningful output since it only shows the wrapper call (but note that var() result is correctly inferred as Float64):

julia> @code_warntype var(randn(5))
Variables:
  #self#::Base.#var
  A::Array{Float64,1}

Body:
  begin 
      return $(Expr(:invoke, MethodInstance for #var#533(::Bool, ::Void, ::Function, ::Array{Float64,1}), :(Base.#var#533), true, :(Base.nothing), :(#self#), :(A)))
  end::Float64
@alyst
Copy link
Contributor Author

alyst commented May 11, 2017

Ah, looks like a dup of #21794. Well, at least it's a reminder to explicitly specify the result type of std()

@nalimilan
Copy link
Member

But why does it work for var then?

@andreasnoack
Copy link
Member

It doesn't if you supply the keyword so the version without keywords is probably handled in a special way. However, to pass the keyword values from std to var we'll have to use keywords even in the default case. Maybe we should get rid of the mean keyword as we have already done for cov and cor.

@alyst
Copy link
Contributor Author

alyst commented May 12, 2017

The "Performance tips" section of the manual is somewhat cryptic and doesn't describe the problem that we see here. The more relevant details are in #10443, #15468.
I'm a little bit lost, because to my understanding the behaviour of std() doesn't fit what is described in the issues: it doesn't look like the specialization on the default keyword argument value is working well.
Would be nice to clarify the situation either by updating the manual or updating the plan for #9551.

@KristofferC
Copy link
Member

julia> using Test

julia> @inferred std(randn(5))
1.369033101041574

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

4 participants