Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/tensors/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,22 @@ function _norm(blockiter, p::Real, init::Real)
return isempty(b) ? init : oftype(init, LinearAlgebra.normInf(b))
end
elseif p > 0 # finite positive p
np = sum(blockiter; init) do (c, b)
return oftype(init, dim(c) * norm(b, p)^p)
np = init
for (c, b) in blockiter
np += dim(c) * norm(b, p)^p
end
return np^(inv(oftype(np, p)))
else
msg = "Norm with non-positive p is not defined for `AbstractTensorMap`"
throw(ArgumentError(msg))
end
end
function LinearAlgebra.norm(t::TensorMap, p::Real = 2)
InnerProductStyle(t) === EuclideanInnerProduct() || throw_invalid_innerproduct(:norm)
# performance specialization:
FusionStyle(sectortype(t)) isa UniqueFusion && return norm(t.data, p)
return _norm(blocks(t), p, float(zero(real(scalartype(t)))))
end

_default_rtol(t) = eps(real(float(scalartype(t)))) * min(dim(domain(t)), dim(codomain(t)))

Expand Down
Loading