Skip to content

Commit d3440a9

Browse files
authored
Remove allocations with norm(x, p). (#679)
The allcations were probably due to lack of proper inlining of the `init=...` keyword, but we're not reducing empty vectors here (there's a special case for that) so we shouldn't need `init` at all.
1 parent 98a5d4d commit d3440a9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/linalg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,13 @@ _norm_p0(x) = x == 0 ? zero(x) : one(x)
267267
return quote
268268
$(Expr(:meta, :inline))
269269
if p == Inf
270-
return mapreduce(abs, max, a; init=$(zero(real(eltype(a)))))
270+
return mapreduce(abs, max, a)
271271
elseif p == 1
272272
@inbounds return $expr_p1
273273
elseif p == 2
274274
return norm(a)
275275
elseif p == 0
276-
return mapreduce(_norm_p0, +, a; init=$(zero(real(eltype(a)))))
276+
return mapreduce(_norm_p0, +, a)
277277
else
278278
@inbounds return ($expr)^(inv(p))
279279
end

0 commit comments

Comments
 (0)