Skip to content

Commit d7ff8af

Browse files
committed
Set alpha to true if unused
1 parent 193f15b commit d7ff8af

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/generic.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,9 @@ _lscale_add!(C::StridedArray, s::Number, X::StridedArray, alpha::Number, beta::N
211211
end
212212
function _lscale_add_nonzeroalpha!(C::AbstractArray, s::Number, X::AbstractArray, alpha::Number, beta::Number)
213213
if isone(alpha)
214-
if iszero(beta)
215-
@. C = s * X
216-
else
217-
@. C = s * X + C * beta
218-
end
214+
# since alpha is unused, we might as well set to `true` to avoid recompiling
215+
# the branch if a different type is used
216+
_lscale_add_nonzeroalpha!(C, s, X, true, beta)
219217
else
220218
if iszero(beta)
221219
@. C = s * X * alpha

test/generic.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,11 @@ end
862862
w = similar(v)
863863
@test mul!(w, 2, v) == 2v
864864
@test mul!(w, v, 2) == 2v
865+
# 5-arg equivalent to the 3-arg method, but with non-Bool alpha
866+
@test mul!(copy!(similar(v), v), 2, v, 1, 0) == 2v
867+
@test mul!(copy!(similar(v), v), v, 2, 1, 0) == 2v
868+
@test mul!(copy!(similar(v), v), 2, v, true, 1) == 3v
869+
@test mul!(copy!(similar(v), v), v, 2, true, 1) == 3v
865870
@test mul!(copy!(similar(v), v), 2, v, 1, 3) == 5v
866871
@test mul!(copy!(similar(v), v), v, 2, 1, 3) == 5v
867872
@test mul!(copy!(similar(v), v), 2, v, 2, 3) == 7v

0 commit comments

Comments
 (0)