I have a function here
function egvalsbyed(m, α, β, l, ϵ0)
nhos = 100
gs = 2.0
H = spzeros(Complex128, 2*nhos, 2*nhos)
for i in 1:nhos
H[i, i] += l^(-2)/m*(i-1+1/2)-gs/(4*m*l^2)
H[i+nhos, i+nhos] += l^(-2)/m*(i-1+1/2)+gs/(4*m*l^2)
if i > 1
H[i+nhos-1, i] += im*√2*α*l^(-1)*√(i-1)
H[i-1, i+nhos] += √2*β*l^(-1)*√(i-1)
end
if i < nhos
H[i+1, i+nhos] += -im*√2*α*l^(-1)*√(i)
H[i+nhos+1, i] += √2*β*l^(-1)*√(i)
end
end
return real.(eigs(H-ϵ0*speye(2*nhos), which=:SM))[1]+ϵ0
end
An example is
julia> egvalsbyed(0.01, 0.05, 0.03, 100.0, 0.4)
6-element Array{Float64,1}:
0.404381
0.395597
0.405545
0.394328
0.38565
0.414433
However, if I do @code_warntype
julia> @code_warntype(egvalsbyed(0.01, 0.05, 0.03, 100.0, 0.4))
Variables:
#self# <optimized out>
m::Float64
α::Float64
β::Float64
l::Float64
ϵ0::Float64
i::Int64
#temp#@_8::Int64
nhos <optimized out>
gs <optimized out>
H::SparseMatrixCSC{Complex{Float64},Int64}
#temp#@_12::Float64
#temp#@_13::Float64
#temp#@_14::Float64
#temp#@_15::Float64
#temp#@_16::Float64
#temp#@_17::Float64
Body:
begin # line 99:
H::SparseMatrixCSC{Complex{Float64},Int64} = $(Expr(:invoke, MethodInstance for spzeros(::Type
{Complex{Float64}}, ::Type{Int64}, ::Int64, ::Int64), :(Base.SparseArrays.spzeros), Complex{Float64}
, :(Base.SparseArrays.Int), :((Base.mul_int)(2, 100)::Int64), :((Base.mul_int)(2, 100)::Int64))) # l
ine 100:
SSAValue(88) = (Base.select_value)((Base.sle_int)(1, 100)::Bool, 100, (Base.sub_int)(1, 1)::In
t64)::Int64
#temp#@_8::Int64 = 1
6:
unless (Base.not_int)((#temp#@_8::Int64 === (Base.add_int)(SSAValue(88), 1)::Int64)::Bool)::Bo
ol goto 209
SSAValue(89) = #temp#@_8::Int64
SSAValue(90) = (Base.add_int)(#temp#@_8::Int64, 1)::Int64
i::Int64 = SSAValue(89)
#temp#@_8::Int64 = SSAValue(90) # line 101:
SSAValue(21) = $(Expr(:invoke, MethodInstance for getindex(::SparseMatrixCSC{Complex{Float64},
Int64}, ::Int64, ::Int64), :(Main.getindex), :(H), :(i), :(i)))
$(Expr(:inbounds, false))
# meta: location intfuncs.jl literal_pow 208
# meta: location math.jl ^ 701
SSAValue(16) = (Base.sitofp)(Float64, -2)::Float64
# meta: location math.jl ^ 699
SSAValue(19) = $(Expr(:foreigncall, "llvm.pow.f64", Float64, svec(Float64, Float64), :(l), 0,
SSAValue(16), 0, :($(Expr(:llvmcall)))))
SSAValue(20) = (Base.add_float)(l::Float64, SSAValue(16))::Float64
# meta: location math.jl nan_dom_err 300
unless (Base.and_int)((Base.ne_float)(SSAValue(19), SSAValue(19))::Bool, (Base.not_int)((Base.
ne_float)(SSAValue(20), SSAValue(20))::Bool)::Bool)::Bool goto 25
#temp#@_12::Float64 = (Base.Math.throw)($(QuoteNode(DomainError())))::Union{}
goto 27
25:
#temp#@_12::Float64 = SSAValue(19)
27:
# meta: pop location
# meta: pop location
# meta: pop location
# meta: pop location
$(Expr(:inbounds, :pop))
SSAValue(2) = $(Expr(:new, Complex{Float64}, :((Base.add_float)((Base.sub_float)((Base.mul_flo
at)((Base.div_float)(#temp#@_12, m)::Float64, (Base.add_float)((Base.sitofp)(Float64, (Base.sub_int)
(i, 1)::Int64)::Float64, (Base.div_float)((Base.sitofp)(Float64, 1)::Float64, (Base.sitofp)(Float64,
2)::Float64)::Float64)::Float64)::Float64, (Base.div_float)(2.0, (Base.mul_float)((Base.mul_float)(
(Base.sitofp)(Float64, 4)::Float64, m)::Float64, (Base.mul_float)(l, l)::Float64)::Float64)::Float64
)::Float64, (Core.getfield)(SSAValue(21), :re)::Float64)::Float64), :((Core.getfield)(SSAValue(21),
:im)::Float64)))
$(Expr(:invoke, MethodInstance for setindex!(::SparseMatrixCSC{Complex{Float64},Int64}, ::Comp
lex{Float64}, ::Int64, ::Int64), :(Main.setindex!), :(H), SSAValue(2), :(i), :(i))) # line 102:
SSAValue(3) = (Base.add_int)(i::Int64, 100)::Int64
SSAValue(4) = (Base.add_int)(i::Int64, 100)::Int64
SSAValue(27) = $(Expr(:invoke, MethodInstance for getindex(::SparseMatrixCSC{Complex{Float64},
Int64}, ::Int64, ::Int64), :(Main.getindex), :(H), SSAValue(3), SSAValue(4)))
$(Expr(:inbounds, false))
# meta: location intfuncs.jl literal_pow 208
# meta: location math.jl ^ 701
SSAValue(22) = (Base.sitofp)(Float64, -2)::Float64
# meta: location math.jl ^ 699
SSAValue(25) = $(Expr(:foreigncall, "llvm.pow.f64", Float64, svec(Float64, Float64), :(l), 0,
SSAValue(22), 0, :($(Expr(:llvmcall)))))
SSAValue(26) = (Base.add_float)(l::Float64, SSAValue(22))::Float64
# meta: location math.jl nan_dom_err 300
unless (Base.and_int)((Base.ne_float)(SSAValue(25), SSAValue(25))::Bool, (Base.not_int)((Base.
ne_float)(SSAValue(26), SSAValue(26))::Bool)::Bool)::Bool goto 50
#temp#@_13::Float64 = (Base.Math.throw)($(QuoteNode(DomainError())))::Union{}
goto 52
50:
#temp#@_13::Float64 = SSAValue(25)
52:
# meta: pop location
# meta: pop location
# meta: pop location
# meta: pop location
$(Expr(:inbounds, :pop))
SSAValue(5) = $(Expr(:new, Complex{Float64}, :((Base.add_float)((Base.add_float)((Base.mul_flo
at)((Base.div_float)(#temp#@_13, m)::Float64, (Base.add_float)((Base.sitofp)(Float64, (Base.sub_int)
(i, 1)::Int64)::Float64, (Base.div_float)((Base.sitofp)(Float64, 1)::Float64, (Base.sitofp)(Float64,
2)::Float64)::Float64)::Float64)::Float64, (Base.div_float)(2.0, (Base.mul_float)((Base.mul_float)(
(Base.sitofp)(Float64, 4)::Float64, m)::Float64, (Base.mul_float)(l, l)::Float64)::Float64)::Float64
)::Float64, (Core.getfield)(SSAValue(27), :re)::Float64)::Float64), :((Core.getfield)(SSAValue(27),
:im)::Float64)))
$(Expr(:invoke, MethodInstance for setindex!(::SparseMatrixCSC{Complex{Float64},Int64}, ::Comp
lex{Float64}, ::Int64, ::Int64), :(Main.setindex!), :(H), SSAValue(5), SSAValue(3), SSAValue(4))) #
line 103:
unless (Base.slt_int)(1, i::Int64)::Bool goto 132 # line 104:
SSAValue(6) = (Base.sub_int)((Base.add_int)(i::Int64, 100)::Int64, 1)::Int64
SSAValue(46) = $(Expr(:invoke, MethodInstance for getindex(::SparseMatrixCSC{Complex{Float64},
Int64}, ::Int64, ::Int64), :(Main.getindex), :(H), SSAValue(6), :(i)))
SSAValue(33) = (Base.Math.sqrt_llvm)((Base.sitofp)(Float64, 2)::Float64)::Float64
$(Expr(:inbounds, false))
# meta: location intfuncs.jl literal_pow 208
# meta: location math.jl ^ 701
SSAValue(28) = (Base.sitofp)(Float64, -1)::Float64
# meta: location math.jl ^ 699
SSAValue(31) = $(Expr(:foreigncall, "llvm.pow.f64", Float64, svec(Float64, Float64), :(l), 0,
SSAValue(28), 0, :($(Expr(:llvmcall)))))
SSAValue(32) = (Base.add_float)(l::Float64, SSAValue(28))::Float64
# meta: location math.jl nan_dom_err 300
unless (Base.and_int)((Base.ne_float)(SSAValue(31), SSAValue(31))::Bool, (Base.not_int)((Base.
ne_float)(SSAValue(32), SSAValue(32))::Bool)::Bool)::Bool goto 77
#temp#@_14::Float64 = (Base.Math.throw)($(QuoteNode(DomainError())))::Union{}
goto 79
77:
#temp#@_14::Float64 = SSAValue(31)
79:
# meta: pop location
# meta: pop location
# meta: pop location
# meta: pop location
$(Expr(:inbounds, :pop))
SSAValue(91) = #temp#@_14::Float64
SSAValue(92) = (Base.Math.sqrt_llvm)((Base.sitofp)(Float64, (Base.sub_int)(i::Int64, 1)::Int64
)::Float64)::Float64
$(Expr(:inbounds, false))
# meta: location operators.jl * 424
SSAValue(42) = (Base.select_value)((Core.getfield)(Main.im, :re)::Bool, SSAValue(33), (Base.co
pysign_float)((Base.sitofp)(Float64, 0)::Float64, SSAValue(33))::Float64)::Float64
SSAValue(43) = (Base.select_value)((Core.getfield)(Main.im, :im)::Bool, SSAValue(33), (Base.co
pysign_float)((Base.sitofp)(Float64, 0)::Float64, SSAValue(33))::Float64)::Float64
SSAValue(44) = (Base.mul_float)(α::Float64, SSAValue(42))::Float64
SSAValue(45) = (Base.mul_float)(α::Float64, SSAValue(43))::Float64
SSAValue(36) = SSAValue(91)
# meta: location operators.jl afoldl 412
SSAValue(40) = (Base.mul_float)(SSAValue(36), SSAValue(44))::Float64
SSAValue(41) = (Base.mul_float)(SSAValue(36), SSAValue(45))::Float64
SSAValue(38) = SSAValue(92)
# meta: pop location
# meta: pop location
$(Expr(:inbounds, :pop))
SSAValue(93) = (Base.mul_float)(SSAValue(38), SSAValue(40))::Float64
SSAValue(94) = (Base.mul_float)(SSAValue(38), SSAValue(41))::Float64
SSAValue(7) = $(Expr(:new, Complex{Float64}, :((Base.add_float)((Core.getfield)(SSAValue(46),
:re)::Float64, SSAValue(93))::Float64), :((Base.add_float)((Core.getfield)(SSAValue(46), :im)::Float
64, SSAValue(94))::Float64)))
$(Expr(:invoke, MethodInstance for setindex!(::SparseMatrixCSC{Complex{Float64},Int64}, ::Comp
lex{Float64}, ::Int64, ::Int64), :(Main.setindex!), :(H), SSAValue(7), SSAValue(6), :(i))) # line 10
5:
SSAValue(8) = (Base.sub_int)(i::Int64, 1)::Int64
SSAValue(9) = (Base.add_int)(i::Int64, 100)::Int64
SSAValue(55) = $(Expr(:invoke, MethodInstance for getindex(::SparseMatrixCSC{Complex{Float64},
Int64}, ::Int64, ::Int64), :(Main.getindex), :(H), SSAValue(8), SSAValue(9)))
SSAValue(53) = (Base.Math.sqrt_llvm)((Base.sitofp)(Float64, 2)::Float64)::Float64
$(Expr(:inbounds, false))
# meta: location intfuncs.jl literal_pow 208
# meta: location math.jl ^ 701
SSAValue(48) = (Base.sitofp)(Float64, -1)::Float64
# meta: location math.jl ^ 699
SSAValue(51) = $(Expr(:foreigncall, "llvm.pow.f64", Float64, svec(Float64, Float64), :(l), 0,
SSAValue(48), 0, :($(Expr(:llvmcall)))))
SSAValue(52) = (Base.add_float)(l::Float64, SSAValue(48))::Float64
# meta: location math.jl nan_dom_err 300
unless (Base.and_int)((Base.ne_float)(SSAValue(51), SSAValue(51))::Bool, (Base.not_int)((Base.
ne_float)(SSAValue(52), SSAValue(52))::Bool)::Bool)::Bool goto 121
#temp#@_15::Float64 = (Base.Math.throw)($(QuoteNode(DomainError())))::Union{}
goto 123
121:
#temp#@_15::Float64 = SSAValue(51)
123:
# meta: pop location
# meta: pop location
# meta: pop location
# meta: pop location
$(Expr(:inbounds, :pop))
SSAValue(95) = (Base.Math.sqrt_llvm)((Base.sitofp)(Float64, (Base.sub_int)(i::Int64, 1)::Int64
)::Float64)::Float64
SSAValue(10) = $(Expr(:new, Complex{Float64}, :((Base.add_float)((Base.mul_float)((Base.mul_fl
oat)((Base.mul_float)(SSAValue(53), β)::Float64, #temp#@_15)::Float64, SSAValue(95))::Float64, (Cor
e.getfield)(SSAValue(55), :re)::Float64)::Float64), :((Core.getfield)(SSAValue(55), :im)::Float64)))
$(Expr(:invoke, MethodInstance for setindex!(::SparseMatrixCSC{Complex{Float64},Int64}, ::Comp
lex{Float64}, ::Int64, ::Int64), :(Main.setindex!), :(H), SSAValue(10), SSAValue(8), SSAValue(9)))
132: # line 107:
unless (Base.slt_int)(i::Int64, 100)::Bool goto 207 # line 108:
SSAValue(11) = (Base.add_int)(i::Int64, 1)::Int64
SSAValue(12) = (Base.add_int)(i::Int64, 100)::Int64
SSAValue(75) = $(Expr(:invoke, MethodInstance for getindex(::SparseMatrixCSC{Complex{Float64},
Int64}, ::Int64, ::Int64), :(Main.getindex), :(H), SSAValue(11), SSAValue(12)))
SSAValue(61) = (Base.Math.sqrt_llvm)((Base.sitofp)(Float64, 2)::Float64)::Float64
$(Expr(:inbounds, false))
# meta: location intfuncs.jl literal_pow 208
# meta: location math.jl ^ 701
SSAValue(56) = (Base.sitofp)(Float64, -1)::Float64
# meta: location math.jl ^ 699
SSAValue(59) = $(Expr(:foreigncall, "llvm.pow.f64", Float64, svec(Float64, Float64), :(l), 0,
SSAValue(56), 0, :($(Expr(:llvmcall)))))
SSAValue(60) = (Base.add_float)(l::Float64, SSAValue(56))::Float64
# meta: location math.jl nan_dom_err 300
unless (Base.and_int)((Base.ne_float)(SSAValue(59), SSAValue(59))::Bool, (Base.not_int)((Base.
ne_float)(SSAValue(60), SSAValue(60))::Bool)::Bool)::Bool goto 151
#temp#@_16::Float64 = (Base.Math.throw)($(QuoteNode(DomainError())))::Union{}
goto 153
151:
#temp#@_16::Float64 = SSAValue(59)
153:
# meta: pop location
# meta: pop location
# meta: pop location
# meta: pop location
$(Expr(:inbounds, :pop))
SSAValue(96) = (Base.neg_int)((Base.and_int)((Base.zext_int)(Int64, (Core.getfield)(Main.im, :
re)::Bool)::Int64, 1)::Int64)::Int64
SSAValue(97) = (Base.neg_int)((Base.and_int)((Base.zext_int)(Int64, (Core.getfield)(Main.im, :
im)::Bool)::Int64, 1)::Int64)::Int64
SSAValue(98) = #temp#@_16::Float64
SSAValue(99) = (Base.Math.sqrt_llvm)((Base.sitofp)(Float64, i::Int64)::Float64)::Float64
$(Expr(:inbounds, false))
# meta: location operators.jl * 424
SSAValue(71) = (Base.mul_float)(SSAValue(61), (Base.sitofp)(Float64, SSAValue(96))::Float64)::
Float64
SSAValue(72) = (Base.mul_float)(SSAValue(61), (Base.sitofp)(Float64, SSAValue(97))::Float64)::
Float64
SSAValue(73) = (Base.mul_float)(α::Float64, SSAValue(71))::Float64
SSAValue(74) = (Base.mul_float)(α::Float64, SSAValue(72))::Float64
SSAValue(65) = SSAValue(98)
# meta: location operators.jl afoldl 412
SSAValue(69) = (Base.mul_float)(SSAValue(65), SSAValue(73))::Float64
SSAValue(70) = (Base.mul_float)(SSAValue(65), SSAValue(74))::Float64
SSAValue(67) = SSAValue(99)
# meta: pop location
# meta: pop location
$(Expr(:inbounds, :pop))
SSAValue(100) = (Base.mul_float)(SSAValue(67), SSAValue(69))::Float64
SSAValue(101) = (Base.mul_float)(SSAValue(67), SSAValue(70))::Float64
SSAValue(13) = $(Expr(:new, Complex{Float64}, :((Base.add_float)((Core.getfield)(SSAValue(75),
:re)::Float64, SSAValue(100))::Float64), :((Base.add_float)((Core.getfield)(SSAValue(75), :im)::Flo
at64, SSAValue(101))::Float64)))
$(Expr(:invoke, MethodInstance for setindex!(::SparseMatrixCSC{Complex{Float64},Int64}, ::Comp
lex{Float64}, ::Int64, ::Int64), :(Main.setindex!), :(H), SSAValue(13), SSAValue(11), SSAValue(12)))
# line 109:
SSAValue(14) = (Base.add_int)((Base.add_int)(i::Int64, 100)::Int64, 1)::Int64
SSAValue(84) = $(Expr(:invoke, MethodInstance for getindex(::SparseMatrixCSC{Complex{Float64},
Int64}, ::Int64, ::Int64), :(Main.getindex), :(H), SSAValue(14), :(i)))
SSAValue(82) = (Base.Math.sqrt_llvm)((Base.sitofp)(Float64, 2)::Float64)::Float64
$(Expr(:inbounds, false))
# meta: location intfuncs.jl literal_pow 208
# meta: location math.jl ^ 701
SSAValue(77) = (Base.sitofp)(Float64, -1)::Float64
# meta: location math.jl ^ 699
SSAValue(80) = $(Expr(:foreigncall, "llvm.pow.f64", Float64, svec(Float64, Float64), :(l), 0,
SSAValue(77), 0, :($(Expr(:llvmcall)))))
SSAValue(81) = (Base.add_float)(l::Float64, SSAValue(77))::Float64
# meta: location math.jl nan_dom_err 300
unless (Base.and_int)((Base.ne_float)(SSAValue(80), SSAValue(80))::Bool, (Base.not_int)((Base.
ne_float)(SSAValue(81), SSAValue(81))::Bool)::Bool)::Bool goto 196
#temp#@_17::Float64 = (Base.Math.throw)($(QuoteNode(DomainError())))::Union{}
goto 198
196:
#temp#@_17::Float64 = SSAValue(80)
198:
# meta: pop location
# meta: pop location
# meta: pop location
# meta: pop location
$(Expr(:inbounds, :pop))
SSAValue(102) = (Base.Math.sqrt_llvm)((Base.sitofp)(Float64, i::Int64)::Float64)::Float64
SSAValue(15) = $(Expr(:new, Complex{Float64}, :((Base.add_float)((Base.mul_float)((Base.mul_fl
oat)((Base.mul_float)(SSAValue(82), β)::Float64, #temp#@_17)::Float64, SSAValue(102))::Float64, (Co
re.getfield)(SSAValue(84), :re)::Float64)::Float64), :((Core.getfield)(SSAValue(84), :im)::Float64))
)
$(Expr(:invoke, MethodInstance for setindex!(::SparseMatrixCSC{Complex{Float64},Int64}, ::Comp
lex{Float64}, ::Int64, ::Int64), :(Main.setindex!), :(H), SSAValue(15), SSAValue(14), :(i)))
207:
goto 6
209: # line 112:
SSAValue(87) = $(Expr(:invoke, MethodInstance for vector_any(::Any, ::Vararg{Any,N} where N),
:(Base.vector_any), :(:which), :(:SM)))
SSAValue(85) = (Base.mul_int)(2, 100)::Int64
SSAValue(86) = $(Expr(:invoke, MethodInstance for *(::Float64, ::SparseMatrixCSC{Float64,Int64
}), :(Main.*), :(ϵ0), :($(Expr(:invoke, MethodInstance for speye_scaled(::Type{Float64}, ::Float64,
::Int64, ::Int64), :(Base.SparseArrays.speye_scaled), Float64, :((Base.sitofp)(Float64, 1)::Float64)
, SSAValue(85), SSAValue(85))))))
return ((Main.getindex)((Base.broadcast)(Main.real, $(Expr(:invoke, MethodInstance for (::Base
.LinAlg.#kw##eigs)(::Array{Any,1}, ::Base.LinAlg.#eigs, ::SparseMatrixCSC{Complex{Float64},Int64}),
:($(QuoteNode(Base.LinAlg.#eigs))), SSAValue(87), :(Main.eigs), :($(Expr(:invoke, MethodInstance for
map(::Base.#-, ::SparseMatrixCSC{Complex{Float64},Int64}, ::SparseMatrixCSC{Float64,Int64}), :(Base
.SparseArrays.map), :(Base.SparseArrays.-), :(H), SSAValue(86)))))))::Any, 1)::Any + ϵ0::Float64)::A
ny
end::Any
Usually, I can guess the meaning of the output of @code_warntype
, but this time I have no clues. What is happening here?