1.

What Does "type-stable" Mean?

Answer»

It means that the type of the output is predictable from the types of the inputs. In PARTICULAR, it means that the type of the output cannot vary depending on the values of the inputs.

The FOLLOWING code is not type-stable:

julia> function unstable(flag::BOOL)

if flag

return 1

else

return 1.0

end

end

unstable (generic function with 1 method)

It returns EITHER an Int or a Float64 depending on the value of its argument. Since Julia can't predict the return type of this function at compile-time, any computation that uses it will have to guard against both types possibly occurring, making generation of fast machine code difficult.

It means that the type of the output is predictable from the types of the inputs. In particular, it means that the type of the output cannot vary depending on the values of the inputs.

The following code is not type-stable:

julia> function unstable(flag::Bool)

if flag

return 1

else

return 1.0

end

end

unstable (generic function with 1 method)

It returns either an Int or a Float64 depending on the value of its argument. Since Julia can't predict the return type of this function at compile-time, any computation that uses it will have to guard against both types possibly occurring, making generation of fast machine code difficult.



Discussion

No Comment Found