Skip to content

Commit

Permalink
Add back simpler Khatri-Rao
Browse files Browse the repository at this point in the history
To save improvements of this function for another more focused PR.
  • Loading branch information
dahong67 committed Mar 1, 2024
1 parent 684af2c commit 9159ef6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/gcp-opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,10 @@ function khatrirao(A::Vararg{T,N}) where {T<:AbstractMatrix,N}
end

# General case: N > 1
r = size(A[1], 2)
all(==(r),size.(A,2)) || throw(DimensionMismatch())
R = ntuple(Val(N)) do k
dims = (ntuple(i -> 1, Val(N - k))..., :, ntuple(i -> 1, Val(k - 1))..., r)
return reshape(A[k], dims)
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])
end
return reshape(broadcast(*, R...), :, r)
return K
end

0 comments on commit 9159ef6

Please sign in to comment.