Dear Chris,

I've managed to get a little better performance by adding a loop and 
avoiding some type conversions.

https://gist.github.com/sdwfrost/8a0e926a5e16d7d104bd2bc1a5f9ed0b

I'm still getting about a 7-fold slowdown from using the function call (as 
an immutable object). How would one make my function F in-place, still 
using a similar generic API?

Best
Simon 

On Thursday, July 21, 2016 at 4:35:56 PM UTC+1, Chris Rackauckas wrote:
>
> 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
>>
>

Reply via email to