Excellent, thanks. Replacing `@inbounds a = dot(W[:,n], state)` with the
following gave a ~5x improvement:
a::Float64 = 0
for k in 1:N
@inbounds a += W[k, n] * state[k]
end
The ::Float64 annotation was necessary or it was really slow. Why does
Julia copy the column before using it in the expression?
Andrew
On Thursday, August 14, 2014 2:40:54 PM UTC+10, John Myles White wrote:
>
> Here are some things you might try:
>
> (1) Don’t use a global const. Pass N as an argument to all functions.
>
> (2) Use in-place multiplication via functions like A_mul_B! in lines like
> `@inbounds a = dot(W[:,n], state)`. In Julia 0.3, W[:,n] creates a copy of
> that column of W on every iteration.
>
> (3) Don’t make full copies of state in lines like `@inbounds samples[:,i]
> = copy(state)`. Do explicit elementwise copying, which is much cheaper.
>
> — John
>
> On Aug 13, 2014, at 9:14 PM, Andrew Wrigley <[email protected]
> <javascript:>> wrote:
>
> > <gibbstiming.jl>
>
>