Hi, thanks for the explanation.
On Wednesday, October 22, 2014 12:15:40 AM UTC+2, Stefan Karpinski wrote: > > > >> However, I really needed to assert the type in all involved arrays before >> using them in the for-loops, or I would loose a factor 10 or thereabouts in >> speed. >> > > This should only be necessary if you're getting these arrays from > non-constant globals or from the fields of a composite type that has > abstractly typed fields. > I don't see immediately how this is the case. All involved arrays were just computed in the lines above the replaced broadcast(). function stats{T<:FloatingPoint}(gmm::GMM, x::Matrix{T}, order::Int) ... sm2p::Matrix{T} = dot(mp, gmm.μ, 2) xx::Matrix{T} = x .* x # nx * d pxx::Matrix{T} = broadcast(+, sm2p', xx * prec') # nx * ng mpx::Matrix{T} = x * mp' # nx * ng ## γ = broadcast(*, a', exp(mpx .- 0.5pxx)) # nx * ng, γ::Matrix{T} = repmat(a', nx) for j = 1:ng for i = 1:nx @inbounds γ[i,j] *= exp(mpx[i,j] - 0.5pxx[i,j]) end end ... I replaced the `γ = broadcast()` with the lines below that. No globals, but perhaps the field type gmm.μ is spoiling things. I am not sure if this is a case of an abstractly typed field type GMM{T<:FloatingPoint} ... μ::Array{T} ... end Should I have written GMM{T2} in the declaration of stats()? Cheers, ---david