Skip to content

Commit

Permalink
Add branches manually in MulAddMul constructor
Browse files Browse the repository at this point in the history
This is suggested by chethega in:
JuliaLang#29634 (comment)
  • Loading branch information
tkf committed Jan 29, 2020
1 parent 9274757 commit ec824ad
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,21 @@ struct MulAddMul{ais1, bis0, TA, TB}
beta::TB
end

MulAddMul(alpha::TA, beta::TB) where {TA, TB} =
MulAddMul{isone(alpha), iszero(beta), TA, TB}(alpha, beta)
@inline function MulAddMul(alpha::TA, beta::TB) where {TA,TB}
if isone(alpha)
if iszero(beta)
return MulAddMul{true,true,TA,TB}(alpha, beta)
else
return MulAddMul{true,false,TA,TB}(alpha, beta)
end
else
if iszero(beta)
return MulAddMul{false,true,TA,TB}(alpha, beta)
else
return MulAddMul{false,false,TA,TB}(alpha, beta)
end
end
end

MulAddMul() = MulAddMul(true, false)

Expand Down

0 comments on commit ec824ad

Please sign in to comment.