I pass a struct (containing pre-allocated arrays for intermediate calculations) to many different functions. My struct looks something like this
struct Workspace
fN_1::MVector{N, Float64}
fN_2::MVector{N, Float64}
fM_1::MVector{M, Float64}
iM_1::MVector{M, Int64}
end
where N
and M
are compile time constants. This works well, but the code does lose readability as the variable names cease to be meaningful: in one function, fN_1
may be time in an intermediate calculation, and in another function it may measure something completely different. Is it possible to refer to a variable by a different name in some local scope?
So, rather than doing
function myfun(w::Workspace, x)
...
for i = 1:N
w.fN_1[i] = ...
end
...
(some calculation using w.fN_1)
end
I first tell Julia that I want to use a different name, so do something like
function myfun(w::Workspace, x)
elapsed_time => w.fN_1
...
for i = 1:N
elapsed_time[i] = ...
end
...
(some calculation using elapsed_time)
end
Thanks.