I have three related questions about specifying types of function arguments and outputs. I'm defining a function f that I expect to call many times, so I'm looking to improve efficiency everywhere I can. My function definition looks something like this:
function f(x, y)
...
return z
end
I know that x will be an Array{Float64,1}, y will be an Array{Float64,2}, and z will be a Float64.
My questions are:
- Is there an efficiency benefit to specifying the types of the inputs
in the function definition, i.e.
function f(x::Array{Float64}, y::Array{Float64})? - Is there any additional benefit to making the types more specific by specifying that
xis 1-dimensional andyis 2-dimensional, i.e.function f(x::Array{Float64,1}, y::Array{Float64,2})? - Is there any efficiency benefit to specifying the type of
z, i.e.function f(x::Array{Float64,1}, y::Array{Float64,2})::Float64?
Thanks so much! And apologies if these questions have been addressed previously.