I have a combination of scalar values, and values stored in vectors. Is there a good way to create a
view of these and send to other functions, rather than allocating it all to a new array?
I am performance de-bugging a piece of code using the profiler. There is a part in it where I check parameter values, and send them on to some DiffEq solver. I do this fairly frequently, and it seems to be a cause for slow down.
DiffEq wants parameter values as a vector, so that is what I am trying to provide. I essentially have a function:
get_p_vector(params,idx) = [find_p_value(params,idx,i) for i in 1:5]
I think the problem is that this allocates a new vector every time, which is causing gc slowdowns. Now, this is not needed, since I do not create any new values. So I should (?) instead have
get_p_vector send a
view, which doesn’t allocate.
Now what happens is that params have (in this case 5) indexes, each holding either a scalar or a vector. I want to create a view of the vector which is either the scalar or the subvector at some idx. E.g.:
param = [1, [2, 20, 200], 3, 4, [5, 50, 500]]
get_p_vector(params,1) should return a view of
[1, 2, 3, 4, 5]
get_p_vector(params,3) a view of
[1, 200, 3, 4, 500]
Now, I am unsure how to do this. I only know how to view of a single array, e.g.
@view my_array[3:10]. Is what I want to do even possible?