# Unusual @code\_warntype behavior in 0.6?

**URL:** <https://discourse.julialang.org/t/unusual-code-warntype-behavior-in-0-6/3414>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [April 28, 2017, 12:37am UTC](https://discourse.julialang.org/t/unusual-code-warntype-behavior-in-0-6/3414 "2017-04-28T00:37:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [April 28, 2017, 12:37am UTC](https://discourse.julialang.org/t/unusual-code-warntype-behavior-in-0-6/3414/1 "2017-04-28T00:37:32Z")

</div>

```julia
eigenvector_centrality(g::AbstractGraph) = norm.(eigs(adjacency_matrix(g), nev=1)[2])

julia> @code_warntype(eigenvector_centrality(g))
Variables:
  #self#::LightGraphs.#eigenvector_centrality
  g::LightGraphs.SimpleGraphs.SimpleGraph{Int64}

Body:
  begin
      SSAValue(0) = $(Expr(:invoke, MethodInstance for (::Base.LinAlg.#kw##eigs)(::Array{Any,1}, ::Base.LinAlg.#eigs, ::SparseMatrixCSC{Int64,Int64}), :($(QuoteNode(Base.LinAlg.#eigs))), :($(Expr(:invoke, MethodInstance for vector_any(::Any, ::Vararg{Any,N} where N), :(Base.vector_any), :(:nev), 1))), :(LightGraphs.eigs), :($(Expr(:invoke, MethodInstance for adjacency_matrix(::LightGraphs.SimpleGraphs.SimpleGraph{Int64}, ::Symbol, ::DataType), :(LightGraphs.adjacency_matrix), :(g), :(:out), :(LightGraphs.Int))))))
      return (Base.broadcast)(LightGraphs.norm, (Base.getfield)(SSAValue(0), 2)::Any)::Any
  end::Any

```

and

```julia
julia> @code_warntype(adjacency_matrix(g))
Variables:
  #self#::LightGraphs.#adjacency_matrix
  g::LightGraphs.SimpleGraphs.SimpleGraph{Int64}

Body:
  begin
      return $(Expr(:invoke, MethodInstance for adjacency_matrix(::LightGraphs.SimpleGraphs.SimpleGraph{Int64}, ::Symbol, ::DataType), :(#self#), :(g), :(:out), :(LightGraphs.Int)))
  end::SparseMatrixCSC{Int64,Int64}

```

Why is the former inferring an `Any` type?

---

<div class="post-metadata">

**Author:** ![fengyang.wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fengyang.wang/32/104_2.png) [@fengyang.wang](https://discourse.julialang.org/u/fengyang.wang)\
**Post date:** [April 28, 2017, 12:49am UTC](https://discourse.julialang.org/t/unusual-code-warntype-behavior-in-0-6/3414/2 "2017-04-28T00:49:14Z")

</div>

`eigs` is type unstable, because it might return a real or a complex matrix, and the compiler doesn’t have enough information to figure out that `norm.(...)` will always be a Float64 matrix. You can fix this by adding a type assertion:

```julia
eigenvector_centrality(g::AbstractGraph) = norm.(eigs(adjacency_matrix(g), nev=1)[2])::Matrix{Float64}

```

---

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [April 28, 2017, 12:52am UTC](https://discourse.julialang.org/t/unusual-code-warntype-behavior-in-0-6/3414/3 "2017-04-28T00:52:33Z")

</div>

@fengyang.wang - thank you. I asserted `Vector{Float64}` and that seemed to do the trick:

```julia
eigenvector_centrality(g::AbstractGraph) =
    vec(norm.(eigs(adjacency_matrix(g), nev=1)[2]))::Vector{Float64}

julia> @code_warntype(eigenvector_centrality(g))
Variables:
  #self#::LightGraphs.#eigenvector_centrality
  g::LightGraphs.SimpleGraphs.SimpleGraph{Int64}

Body:
  begin
      SSAValue(0) = $(Expr(:invoke, MethodInstance for (::Base.LinAlg.#kw##eigs)(::Array{Any,1}, ::Base.LinAlg.#eigs, ::SparseMatrixCSC{Int64,Int64}), :($(QuoteNode(Base.LinAlg.#eigs))), :($(Expr(:invoke, MethodInstance for vector_any(::Any, ::Vararg{Any,N} where N), :(Base.vector_any), :(:nev), 1))), :(LightGraphs.eigs), :($(Expr(:invoke, MethodInstance for adjacency_matrix(::LightGraphs.SimpleGraphs.SimpleGraph{Int64}, ::Symbol, ::DataType), :(LightGraphs.adjacency_matrix), :(g), :(:out), :(LightGraphs.Int))))))
      return (Core.typeassert)((LightGraphs.vec)((Base.broadcast)(LightGraphs.norm, (Base.getfield)(SSAValue(0), 2)::Any)::Any)::Any, Array{Float64,1})::Array{Float64,1}
  end::Array{Float64,1}

```
