Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure in LinearAlgebra/addmul for 5-way mul! with BigFloat and Bidiagonal #55781

Closed
giordano opened this issue Sep 15, 2024 · 1 comment · Fixed by #56210
Closed

Test failure in LinearAlgebra/addmul for 5-way mul! with BigFloat and Bidiagonal #55781

giordano opened this issue Sep 15, 2024 · 1 comment · Fixed by #56210
Labels
bignums BigInt and BigFloat bug Indicates an unexpected problem or unintended behavior linear algebra Linear algebra test This change adds or pertains to unit tests

Comments

@giordano
Copy link
Contributor

giordano commented Sep 15, 2024

On 4633607 with Linux (either x86_64 or aarch64) I get

julia> Base.runtests("LinearAlgebra/addmul"; seed=0xca081a1e9adc6829030ff209636c84f4)
[...]
The global RNG seed was 0xca081a1e9adc6829030ff209636c84f4.

Error in testset LinearAlgebra/addmul:
Test Failed at ~/repo/julia/usr/share/julia/stdlib/v1.12/LinearAlgebra/test/addmul.jl:192
  Expression: ≈(collect(returned_mat), α * Ac * Bc + β * Cc, rtol = rtol)
   Evaluated: BigFloat[-0.0001400037216701636132108987549395176373104782747840190352000128617941687774417292;;] ≈ BigFloat[-0.0001400633263149390038358987549395176373104782747840190352000128617941687774417292;;] (rtol=0.00034526697709225118160247802734375)

Reduced to

julia> using LinearAlgebra

julia> α, β = true, big"1.4598638281754612311402752311551012098789215087890625";

julia> C = [big"-2.432162727109652065274123009949748377821320641416554145536270759853570050001279";;];

julia> Cc = collect(C);

julia> Af = Float32[0.50721234;;];

julia> Ac = collect(Af);

julia> Bf = Bidiagonal([7], Int64[], :U);

julia> Bc = [7;;];

julia> returned_mat = mul!(C, Af, Bf, α, β)
1×1 Matrix{BigFloat}:
 -0.0001400037216701636132108987549395176373104782747840190352000128617941687774417292

julia> α * Ac * Bc + β * Cc
1×1 Matrix{BigFloat}:
 -0.0001400633263149390038358987549395176373104782747840190352000128617941687774417292

Somewhat distressfully, this doesn't reproduce on aarch64-darwin, in the sense that the above reproducer gives

julia> returned_mat = mul!(C, Af, Bf, α, β)
1×1 Matrix{BigFloat}:
 -0.0001400633263149390038358987549395176373104782747840190352000128617941687774417292

julia> α * Ac * Bc + β * Cc
1×1 Matrix{BigFloat}:
 -0.0001400633263149390038358987549395176373104782747840190352000128617941687774417292
@giordano giordano added bug Indicates an unexpected problem or unintended behavior linear algebra Linear algebra bignums BigInt and BigFloat test This change adds or pertains to unit tests labels Sep 15, 2024
@jishnub
Copy link
Contributor

jishnub commented Sep 16, 2024

The structured arrays seem to be a red herring in this one, and the issue may be reproduced using only Matrixes. Reduced further:

julia> α * Ac * Bc + β * C
1×1 Matrix{BigFloat}:
 -0.0001400633263149390038358987549395176373104782747840190352000128617941687774417292

julia> mul!(copy(C), Ac, Bc, α, β)
1×1 Matrix{BigFloat}:
 -0.0001400037216701636132108987549395176373104782747840190352000128617941687774417292

In the out-of-place case, the first multiplication α * Ac * Bc is carried out in Float32 precision, whereas in the second case, all the numbers are promoted to BigFloat first before the multiplication is carried out. This seems to explain the differences in the numbers:

julia> mul!(Float32.(zero(C)), Ac, Bc, α, false) + C * β
1×1 Matrix{BigFloat}:
 -0.0001400633263149390038358987549395176373104782747840190352000128617941687774417292

julia> mul!(zero(C), Ac, Bc, α, false) + C * β
1×1 Matrix{BigFloat}:
 -0.0001400037216701636132108987549395176373104782747840190352000128617941687774417292

Worth noting that the two terms being added are similar in magnitude and with opposite signs, so the rounding differences play a part.

julia>* Ac * Bc)[1], (β * C)[1]
(3.5504863f0, -3.550626389543966306191335898754939517637310478274784019035200012861794168777442)

Since we end up comparing numbers close to zero, perhaps we need an atol here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bignums BigInt and BigFloat bug Indicates an unexpected problem or unintended behavior linear algebra Linear algebra test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants