Skip to content
Merged
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
20 changes: 4 additions & 16 deletions src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -579,20 +579,14 @@ function generic_norm2(x)
T = typeof(maxabs)
if isfinite(length(x)*maxabs*maxabs) && !iszero(maxabs*maxabs) # Scaling not necessary
sum::promote_type(Float64, T) = norm_sqr(v)
while true
y = iterate(x, s)
y === nothing && break
(v, s) = y
for v in Iterators.rest(x, s)
sum += norm_sqr(v)
end
ismissing(sum) && return missing
return convert(T, sqrt(sum))
else
sum = abs2(norm(v)/maxabs)
while true
y = iterate(x, s)
y === nothing && break
(v, s) = y
for v in Iterators.rest(x, s)
sum += (norm(v)/maxabs)^2
end
ismissing(sum) && return missing
Expand All @@ -614,21 +608,15 @@ function generic_normp(x, p)
spp::promote_type(Float64, T) = p
if -1 <= p <= 1 || (isfinite(length(x)*maxabs^spp) && !iszero(maxabs^spp)) # scaling not necessary
sum::promote_type(Float64, T) = norm(v)^spp
while true
y = iterate(x, s)
y === nothing && break
(v, s) = y
for v in Iterators.rest(x, s)
ismissing(v) && return missing
sum += norm(v)^spp
end
return convert(T, sum^inv(spp))
else # rescaling
sum = (norm(v)/maxabs)^spp
ismissing(sum) && return missing
while true
y = iterate(x, s)
y === nothing && break
(v, s) = y
for v in Iterators.rest(x, s)
ismissing(v) && return missing
sum += (norm(v)/maxabs)^spp
end
Expand Down