Below is just an MWE for the concept (I am using dummy equations).
I have main code in mani.jl
which includes another file subi.jl
. The main code calls function ini(args)
to calculate mat
which is useful only in function update
(located in subi.jl
).
Since update
is being called within for loop
and transferring the argument mat
at each iteration could be costly (when it is very big). So, is there a way to let ini()
creates and defines mat
only inside the file subi.jl
(maybe by adding some lines), so I can then call only by two arguments, i.e., update(R,i)
###################### subi.jl ######################
using SparseArrays, LinearAlgebra
function ini(data)
mat = sparse(1:length(data), [4,6,7,7,8,9], d);
mat;
end
function update(R,mat,i)
R .+= mat .* i;
end
###################### maini.jl ######################
using SparseArrays, LinearAlgebra
include("subi.jl");
d = [10,20,30,40,50,60];
mat = ini(d)
R = copy(mat);
function run(mat,R)
for i in 1:100
update(R,mat,i)
end
end
run(mat,R);