Skip to content

Commit ba8b30a

Browse files
committed
Move iteration to within _generic_normp
1 parent 3261d84 commit ba8b30a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/generic.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,19 +600,18 @@ end
600600
# Compute L_p norm ‖x‖ₚ = sum(abs(x).^p)^(1/p)
601601
# (Not technically a "norm" for p < 1.)
602602
function generic_normp(x, p)
603-
(v, s) = iterate(x)::Tuple
604603
if p > 1 || p < -1 # might need to rescale to avoid overflow
605604
maxabs = p > 1 ? normInf(x) : normMinusInf(x)
606605
(ismissing(maxabs) || iszero(maxabs) || isinf(maxabs)) && return maxabs
607606
return _generic_normp(x, p, maxabs)
608607
else
609-
# in this case, only the type of the last argument is used
610-
# there is no scaling involved
611-
return _generic_normp(x, p, float(norm(v)))
608+
return _generic_normp(x, p)
612609
end
613610
end
614611

615-
function _generic_normp(x, p, maxabs::T) where {T}
612+
function _generic_normp(x, p, maxabs::TM = nothing) where {TM}
613+
(v, s) = iterate(x)::Tuple
614+
T = isnothing(maxabs) ? typeof(float(norm(v))) : TM
616615
spp::promote_type(Float64, T) = p
617616
if -1 <= p <= 1 || (isfinite(length(x)*maxabs^spp) && !iszero(maxabs^spp)) # scaling not necessary
618617
sum::promote_type(Float64, T) = norm(v)^spp

0 commit comments

Comments
 (0)