I’m currently running into a situation where my functions need to operate on many potentially huge matrices of slightly different sizes. I preallocate all memory first, such that all functions take elements from some of the input arguments, do a computation and store it in one of the others, e.g.
function rhs!(U,V,A,B,C,D,E,F,G)
func1!(U,V,A,B)
func2!(U,V,C,D)
func3!(U,V,D,E)
func4!(U,V,F,G)
end
If I have more like 30+ arguments I can’t even be bothered to write ::AbstractMatrix for readability. Inside rhs! many of the matrices are read&write, some are read-only (U,V in this example). In almost all cases I am also totally fine if the variable names are the same inside the function and in the outer scope:
U,V = preallocate1(...)
A,B,C,D,E,F,G,H = preallocate2(...)
for i in 1:n
...
rhs!(U,V,A,B,C,D,E,F,G,H)
...
end
Is there a recommended way how to maintain readability whilst declaring everything correctly and avoiding zipping into tuples and unpacking the variables? I guess, technically I could set A,B,C,… as constants, and not pass them on as an argument but then everytime I store some new entries in them I would get a redefining constant warning.