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:
function f(x::Array{Float64}, y::Array{Float64})
?x
is 1-dimensional and y
is 2-dimensional, i.e. function f(x::Array{Float64,1}, y::Array{Float64,2})
?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.
In general, no (to all questions). The beauty of Julia is that its compiler is excellent at figuring these things out for you on the fly. The performance tips is the best place to look for how to write efficient code, like making sure your function is type-stable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With