julia lang - Updating vector to avoid excess memory use -
i have function returns vector. since call function many times, want update vector provide rather create new vector. avoid use of memory , increase speed.
the original code looks like:
function!(prob1,pi,prob0) prob1=pi'*prob0 return prob1 end
of course creates new prob1 vector each time. i've attempted amend in 2 different ways:
function!(prob1,pi,prob0) in 1:length(prob1) prob1[i]=pi[:,i]'*prob0 end return prob1 end #or function!(prob1,pi,prob0) in 1:length(prob1) prob1[i]=dot(pi[:,i],prob0) end return prob1 end
however, both run slower original code although use less memory. suggestions improving performance time great.
you don't need define function, there 1 (albeit undocumented): at_mul_b!(prob1,pi,prob0)
should give want.
Comments
Post a Comment