Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

How @code_warntype , precompilation, execution and type interference works?

$
0
0

Hey Julianners,

I found a really strange behavior! But shit is pretty serious thing all in all.

using InteractiveUtils
struct me{I,O}
	a::Vector{Array{Float32,I}}
	b::Vector{Array{Float32,O}}
end

double(x::Vector{Array{Float32, 3}}) = 2 .* x

function foo(n) 
	double(n.a)
end

function bar()
	m=me{3,2}([randn(Float32,2,3,4)],[randn(Float32,2,4)])
	foo(m)
end
@code_warntype bar()

So bar is an uninterferable thing… which is strange… But ok.
Then running this code snippet:

@time  bar();
@code_warntype bar()
double(x::Vector{Array{Float32, 3}}) = 2 .* x
@code_warntype bar()

After redefining double(…), bar() becomes an interferable class!! :face_with_raised_eyebrow:

What is going on here?

11 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Latest Images

Trending Articles



Latest Images