![](/img/trans.png)
[英]Why does a pointer to array need to be cast before being passed as parameter to a function with array type argument?
[英]Why does julia not recognize the type of an array that is passed as a function argument, listing it as Any instead?
我在julia中定義了一個接受向量的函數(特別是Vector{Complex128}
)。 當我查看@code_warntype
的輸出時,我看到變量類型被列為Any
。 據我了解,這可能會影響速度。 這是代碼的簡單版本,例如:
function abc(h::Vector{Complex128})
a=1+2
end
@code_warntype
的輸出是
julia> @code_warntype abc(zeros(Complex128,2))
Variables:
#self#::#abc
h::Any
a::Int64
Body:
begin
SSAValue(0) = (Base.add_int)(1, 2)::Int64
return SSAValue(0)
end::Int64
變量h
的類型列為Any
。 我是julia的新手,真的不知道我是否在這里缺少任何東西。 這種行為似乎並沒有具體到Vector{Complex128}
,我得到了相同的行為Vector{Float64}
也。 我是在這里錯誤地注釋了變量類型,還是應該這樣工作? 如果有的話,我正在使用julia v0.6.0。
這是因為編譯器已經對其進行了優化,因此它甚至不存在。 v0.6.1中更改了它的打印方式,使其更加清晰:
julia> function abc(h::Vector{Complex128})
a=1+2
end
abc (generic function with 1 method)
julia> @code_warntype abc(zeros(Complex128,2))
Variables:
#self# <optimized out>
h <optimized out>
a <optimized out>
Body:
begin
SSAValue(0) = (Base.add_int)(1, 2)::Int64
return SSAValue(0)
end::Int64
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.