> The (global) constants are nvar = 6, number of variables (Int64) and plags
> = 6, number of lags in the vector autoregression (Int64), which are defined
> previously in the programs.
did you actually declare those const:
const nvar=6
?
If not, this will impact your loop.
> function bb_update(bbj, bbcovj)
>
> for j = 1:obs
> bbcovj += capZ[(j-1)*nvar+1:j*nvar,:]'*(
> inv(Om_e[(j-1)*nvar+1:j*nvar,:]) )*capZ[(j-1)*nvar+1:j*nvar,:] ;
> bbj += capZ[(j-1)*nvar+1:j*nvar,:]'*(
> inv(Om_e[(j-1)*nvar+1:j*nvar,:]) )*yyy[:,j] ;
> end
>
> return (bbj, bbcovj)
> end
Any object you do not pass in as argument needs to be const, thus maybe
pass them as arguments instead:
function bb_update(bbj, bbcovj, yyy, Om_e, capZ)
for j = 1:size(yyy,2)
jj = (j-1)*nvar+1:j*nvar
bbcovj += capZ[jj,:]'*(inv(Om_e[jj,:]) )*capZ[jj,:]
bbj += capZ[jj,:]'*(inv(Om_e[jj,:]) )*yyy[:,j]
end
return (bbj, bbcovj)
end
Also, note, Julia is fastest with unrolled loops as at the moment Julia
makes a copy when doing slices (this will change sometime). However, as
you're doing an matrix inverse, that trick is not applicable here.
Have you seen the performance section in the manual?