From 8c31d59b5797f4329afda88d03b20d57257f8df6 Mon Sep 17 00:00:00 2001 From: David Hong Date: Tue, 20 Aug 2024 11:57:28 -0400 Subject: [PATCH] Simplify implementation --- src/cpd.jl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/cpd.jl b/src/cpd.jl index b97f6f0..967e53d 100644 --- a/src/cpd.jl +++ b/src/cpd.jl @@ -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)