Skip to content

Commit

Permalink
Avoid making two copies of K
Browse files Browse the repository at this point in the history
1. use `reduce` to compute all but the last `kron`
2. use `kron!` for the last one
  • Loading branch information
dahong67 committed Mar 1, 2024
1 parent 8f57eef commit b0a6d2b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/gcp-opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ function khatrirao(A::Vararg{T,N}) where {T<:AbstractMatrix,N}
r = (only unique)(size.(A, 2))
K = similar(A[1], prod(size.(A, 1)), r)
for j in 1:r
K[:, j] = reduce(kron, [view(A[i], :, j) for i in 1:N])
temp = reduce(kron, [view(A[i], :, j) for i in 1:N-1])
kron!(view(K, :, j), temp, view(A[N], :, j))
end
return K
end

0 comments on commit b0a6d2b

Please sign in to comment.