Skip to content

Commit

Permalink
Simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dahong67 committed Aug 20, 2024
1 parent 4c50953 commit 8c31d59
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/cpd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ function getindex(M::CPD{T,N}, I::Vararg{Int,N}) where {T,N}
end
getindex(M::CPD{T,N}, I::CartesianIndex{N}) where {T,N} = getindex(M, Tuple(I)...)

function Array(A::CPD)
λ = A.λ
K = TensorKernels.khatrirao(reverse(A.U)...)
vecM = K * λ
reshaped_result = reshape(vecM, size(A)...)
return reshaped_result
end;
Array(A::CPD) = reshape(TensorKernels.khatrirao(reverse(A.U)...) * A.λ, size(A))

norm(M::CPD, p::Real = 2) =
p == 2 ? norm2(M) : norm((M[I] for I in CartesianIndices(size(M))), p)
Expand Down

0 comments on commit 8c31d59

Please sign in to comment.