Skip to content

Commit

Permalink
Make sure result is an Array
Browse files Browse the repository at this point in the history
  • Loading branch information
dahong67 committed Aug 20, 2024
1 parent 8c31d59 commit 7fda495
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/GCPDecompositions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module GCPDecompositions
# Imports
import Base: ndims, size, show, summary
import Base: getindex
import Base: Array
import Base: AbstractArray, Array
import LinearAlgebra: norm
using IntervalSets: Interval
using Random: default_rng
Expand Down
3 changes: 2 additions & 1 deletion src/cpd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ 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)...)

Array(A::CPD) = reshape(TensorKernels.khatrirao(reverse(A.U)...) * A.λ, size(A))
AbstractArray(A::CPD) = reshape(TensorKernels.khatrirao(reverse(A.U)...) * A.λ, size(A))
Array(A::CPD) = Array(AbstractArray(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 7fda495

Please sign in to comment.