diff --git a/src/cpd.jl b/src/cpd.jl index a6f87d2..92b7db7 100644 --- a/src/cpd.jl +++ b/src/cpd.jl @@ -79,11 +79,11 @@ end function getindex(M::CPD{T,N}, I::Vararg{Int,N}) where {T,N} @boundscheck Base.checkbounds_indices(Bool, axes(M), I) || Base.throw_boundserror(M, I) - return sum( - M.λ[j] * prod(M.U[k][I[k], j] for k in Base.OneTo(ndims(M))) for - j in Base.OneTo(ncomponents(M)); - init = zero(eltype(T)), - ) + val = zero(eltype(T)) + for j in Base.OneTo(ncomponents(M)) + val += M.λ[j] * prod(M.U[k][I[k], j] for k in Base.OneTo(ndims(M))) + end + return val end getindex(M::CPD{T,N}, I::CartesianIndex{N}) where {T,N} = getindex(M, Tuple(I)...)