Is preallocation possible for repeated calculation of trajectory of a discrete model (DynamicalSystems.jl)?

I need to analyze the following discrete model in r-k parametric space,

function test_difference_eq(x,par,n)
   r, k = par
   a = 5.0; mu = 0.5; d = 0.2;
   dx = x[1]*exp(r*(1-x[1]/k)-x[2]/(a+x[1]^2))
   dy = x[2]*exp(mu*x[1]/(a+x[1]^2)-d)
   return @SVector [dx, dy]

I used DynamicalSystems.jl and calculated the trajectories inside two for loops (nested):

for i = 1:xpts         
     for j = 1:ypts
          set_parameter!(ds, [par1[i], par2[j]])
          tr = trajectory(ds, NIter; Ttr=NTr)
          # do the analysis here on tr[:,1] 
          # for example, period = seqper(tr[:,1])

Can tr be preallocated? Also tr[:,1] makes its own allocation. @view tr[:,1] doesn’t work with Dataset used in DynamicalSystems.jl

Any help?

Thanks in advance.

Full code can be found here.

ask people who maintain this package

1 Like

I don’t know where should I ask. Can anyone show me?

Alternatively, can I extend the package by adding another version of trajectory that accepts an array for solution and then modifies it, Will it be helpful?

For packages located on github, you can usually open an issue on their repository (found here) and in it ask about adding a function trajectory! that takes a preallocated vector as input.

Yeah, that should be possible by defining DynamicalSystems.trajectory!. If you add that function to the issue (or directly create a PR, with it being added in the appropriate place) it will probably be appreciated by the maintainers.