The Devectorize package should help you here in keeping your code clean 
while getting explicit-loop-like performance.

On Wednesday, July 9, 2014 4:05:23 PM UTC-4, Steven G. Johnson wrote:
>
>
>
> On Wednesday, July 9, 2014 1:59:46 PM UTC-4, Steve Bellan wrote:
>>
>> Hi Josh, thanks for the response. I've managed to get a working version 
>> up with an Array. Its about twice as fast as R and I'm wondering if there 
>> are still ways I can speed it up. Here's the Julia version:
>>
>>
>> (s__, mb_a1, mb_a2, mb_, f_ba1, f_ba2, f_b, hb1b2, hb2b1) = 1:9
>> function pre_coupleMat(serostates, sexually_active) 
>>     temp = serostates[sexually_active,:]
>>     serostates[sexually_active,s__]   = temp[:,s__] .* (1-p_m_bef) .* (1-
>> p_f_bef)
>>
>
> This will be way faster if you just write out a loop to update the 
> serostates array.
>
> The problem with your current code is that it allocates zillions of little 
> temporary arrays, which is always a slow thing to do in a 
> performance-critical function.    Not only do you have temp, but every .* 
> operation allocates a temporary array for its result.
>
> That will make the code longer and a bit uglier, unfortunately, but 
> basically you need C-like inner-loop code for C-like performance.
>

Reply via email to