Dear Julia community,
I wish to learn the appropriate usage of Julia tuples.
Consider the following scenario. One needs to make an inline function to separate a block of code inside a very complicated function. Naturally, this block of code operates with several local variables. When making the inline function, these local variables are passed into the inline function as arguments. More importantly, the inline function returns several variables after some operations. Since the inline function has its own scope, inside the inline function one cannot directly assign values to the variables from the caller, but rather return some variables. For example, I have made the following inline function:
@inline function compute_something(v1, v2, v3, v4)
#...
# some computations
return (r1, r2, r3, r4, r5)
end
This inline function compute_something()
separates the code inside a complicated function COMP()
, which has local variables v1, v2, v3, v4, r1, r2, r3, r4, r5
. I hope to use it inside COMP()
as following
function COMP()
# ...
# some computations that prepares v1, v2, v3, v4
(u1, u2, u3, u4, u5) = compute_something(v1, v2, v3, v4)
# continue ...
end
Now the real question is performance: does this tuple assignment actually create a tuple and assign? Or it just paste the code of inline function into COMP()
and assign the results of compute_something()
to the local variables u1, u2, u3, u4, u5
inside COMP()
, as if I write u1 = r1
, u2 = r2
, … ?