Thank you, I had the opportunity to try out some of the suggestions.
For example, the resid = Y - X * beta_d;
trick reduced the allocations of sigma from 7 to 44, I would watch out for such points in the future.
mine
julia> @time genSigma(Y,X,beta_d,nu0,d0)
0.000013 seconds (7 allocations: 5.016 KiB)
0.10240049561807199
dot trick:
julia> @time genSigma(Y,X,beta_d,nu0,d0)
0.000016 seconds (4 allocations: 2.516 KiB)
0.08709325471913029
and simply that reduced the total code by almost a half (and allocations by a lot)!
julia> @time include("MainNewB.jl")
0.048585 seconds (150.56 k allocations: 51.639 MiB, 9.80% gc time)
vs
julia> @time include("MainNewB.jl")
0.074861 seconds (171.56 k allocations: 68.732 MiB, 11.86% gc time)
I am at that amount of seconds that I should start using BenchmarkTools
I am unsure how to incorporate the "!"
suggestion (just changing the values of beta_d
instead of re-allocating it. I tried following the advice in this discussion, more specifically to use x=f(x)
as in this post
I tried pre-defining beta_d in gibbs
such that
function gibbs(Y,X,BETA0,Sigma0,sig2_d,d0,nu0,n_gibbs,burn)
beta_d = zeros(5,1)
...
for i = 1:n_gibbs
beta_d = genBeta(X,Y,BETA0,Sigma0,sig2_d,beta_d)
...
end
and then in genBeta
assigning to beta_d’s elements but that doesn’t seem to be it.
beta_d[:,1] = Beta1 + C.L*randn(5,1)
alternatively I tried beta_d .=
.
What is the correct way to go about this? Just a reference to the manual can also help, I couldn’t find easily functions with the "!"
operator. I looked at the broadcast
part and I thought I can follow but obviously I didn’t implement it well as I don’t see any changes to the allocations, nor time.