Skip to content

Commit

Permalink
Fix zero alpha and complex eltypes
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Oct 17, 2024
1 parent ecba575 commit ac969c1
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions stdlib/LinearAlgebra/test/addmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,21 @@ function compare_matmul(C, A, B, α, β,
rtol = max(rtoldefault.(real.(eltype.((C, A, B))))...,
rtoldefault.(real.(typeof.((α, β))))...);
Ac = collect(A), Bc = collect(B), Cc = collect(C))
Ccopy = copy(C)
returned_mat = mul!(Ccopy, A, B, α, β)
@test returned_mat === Ccopy
atol = max(maximum(epsfloateltype, (C,A,B)),
maximum(epsfloattypeof, (α,β)))
exp_val = Ac * Bc * strongzero(α) + Cc * strongzero(β)
@test collect(returned_mat) exp_val rtol=rtol atol=atol
rtol_match = isapprox(collect(returned_mat), exp_val, rtol=rtol)
if !(rtol_match || β isa Bool || isapprox(β, 0, atol=eps(typeof(β))))
negβ = -β
returned_mat = mul!(copy(C), A, B, α, negβ)
exp_val = Ac * Bc * strongzero(α) + Cc * negβ
@testset let A=A, B=B, C=C, α=α, β=β
Ccopy = copy(C)
returned_mat = mul!(Ccopy, A, B, α, β)
@test returned_mat === Ccopy
atol = max(maximum(epsrealfloateltype, (C,A,B)),
maximum(epsrealfloattypeof, (α,β)))
exp_val = Ac * Bc * strongzero(α) + Cc * strongzero(β)
@test collect(returned_mat) exp_val rtol=rtol atol=atol
rtol_match = isapprox(collect(returned_mat), exp_val, rtol=rtol)
if !(rtol_match || β isa Bool || isapprox(β, 0, atol=eps(typeof(β))))
negβ = -β
returned_mat = mul!(copy(C), A, B, α, negβ)
exp_val = Ac * Bc * strongzero(α) + Cc * negβ
@test collect(returned_mat) exp_val rtol=rtol atol=atol
end
end
end

Expand Down Expand Up @@ -218,7 +220,7 @@ end
@testset "α = 0 ignores A .= NaN" begin
Acopy = copy(A)
parent(Acopy) .= NaN
compare_matmul(C, Acopy, B, α, zero(eltype(C)), rtol; Ac, Bc, Cc)
compare_matmul(C, Acopy, B, zero(eltype(A)), β, rtol; Ac, Bc, Cc)
end
end
end
Expand Down

0 comments on commit ac969c1

Please sign in to comment.