You can change line 70 to be in place with a loop: for i in 1:length(x) x[i] = x[i] + deltax[i] end
I don't think you can do x[:] =x .+deltax as fancy syntax here since the x is part of the statement though (you can check). This should cut out an allocation here and bring down the time. Do you need to use a WeightVec? If you do (for future things), keep the WeightVec separate from the Vector so that the types aren't changing. let wpf always be the WeightVec you make from pf. Otherwise pf isn't type stable. It would be best if you could make F in-place as well since this is where your bottleneck is. On Thursday, July 21, 2016 at 7:56:51 AM UTC-7, Simon Frost wrote: > > Dear All, > > I'm having some issues with code speed for some Gillespie type > simulations. The toy model is described here: > > > http://phylodynamics.blogspot.co.uk/2013/06/comparing-performance-of-r-and-rcpp-for.html > http://phylodynamics.blogspot.co.uk/2013/06/an-sir-model-in-julia.html > > I get good performance with my vanilla Julia code, but a more generic > implementation is slower: > > http://github.com/sdwfrost/Gillespie.jl > > The gist is here: > > https://gist.github.com/sdwfrost/1b4bce19faf2d7b8624cac048a36f32d > > Lines 57 and 70 appear to be the culprit: > > https://github.com/sdwfrost/Gillespie.jl/blob/master/src/SSA.jl > > I've tried some devectorisation, but in my hackery, I appear to get side > effects, where the argument x0 passed to the ssa function is modified. Any > tips? > > Best > Simon >
