In 'Julia High Performance' (2nd Ed.), the author gives the following example to explain how to obtain type stability in loops:
function simdsum_fixed(x)
s = zero(eltype(x))
@simd for v in A
s += v
end
return s
end
In a previous example, with different code they simply use zero(x). I've therefore tried the same function without eltype() as below (simdsum_fixed_b). They seem to work in the same way.
function simdsum_fixed_b(x)
s = zero(x)
@simd for v in A
s += v
end
return s
end
How is then zero(eltype(x)) different from zero(x)? What is the advantage of using the first over the second?
Thanks in advance.