From 55b9d0aa59953a29f1f5b412681fd3142970480a Mon Sep 17 00:00:00 2001 From: Thomas Christensen Date: Fri, 18 Oct 2024 11:36:34 +0200 Subject: [PATCH] use `@assume_effects :terminates_locally` on `bezout`, similarly to `gcdx` - also flip output order to align with `gcdx`'s --- .vendor/SmithNormalForm/src/bezout.jl | 12 ++++++------ .vendor/SmithNormalForm/src/snf.jl | 4 ++-- .vendor/SmithNormalForm/test/runtests.jl | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.vendor/SmithNormalForm/src/bezout.jl b/.vendor/SmithNormalForm/src/bezout.jl index 97a27b50..ffb16e5f 100644 --- a/.vendor/SmithNormalForm/src/bezout.jl +++ b/.vendor/SmithNormalForm/src/bezout.jl @@ -4,16 +4,16 @@ Calculates Bézout coefficients. This is analogous to `gcdx`, and solves the same problem, but does not necessarily return identical solutions. """ -function bezout(a::R, b::R) where {R} +Base.@assume_effects :terminates_locally function bezout(a::R, b::R) where {R} rev = a < b x, y = rev ? (a,b) : (b,a) s0, s1 = oneunit(R), zero(R) t0, t1 = zero(R), oneunit(R) - while y != zero(R) - q = div(x, y) - x, y = y, x - y * q + while !iszero(y) + q, r = divrem(x, y) + x, y = y, r s0, s1 = s1, s0 - q * s1 t0, t1 = t1, t0 - q * t1 end @@ -21,7 +21,7 @@ function bezout(a::R, b::R) where {R} s, t = rev ? (s0, t0) : (t0, s0) g = x - if g == a + if g == a # differs from `gcdx` here (also in `rev` clauses above) s = one(R) t = zero(R) elseif g == -a @@ -29,5 +29,5 @@ function bezout(a::R, b::R) where {R} t = zero(R) end - return s, t, g + return g, s, t end diff --git a/.vendor/SmithNormalForm/src/snf.jl b/.vendor/SmithNormalForm/src/snf.jl index 1865fbf2..5a428582 100644 --- a/.vendor/SmithNormalForm/src/snf.jl +++ b/.vendor/SmithNormalForm/src/snf.jl @@ -84,7 +84,7 @@ function rowpivot(U::AbstractArray{R,2}, (iszero(b) || i == k) && continue a = D[i,j] - s, t, g = bezout(a, b) + g, s, t = bezout(a, b) x = divide(a, g) y = divide(b, g) @@ -103,7 +103,7 @@ function colpivot(V::AbstractArray{R,2}, (iszero(b) || j == k) && continue a = D[i,j] - s, t, g = bezout(a, b) + g, s, t = bezout(a, b) x = divide(a, g) y = divide(b, g) diff --git a/.vendor/SmithNormalForm/test/runtests.jl b/.vendor/SmithNormalForm/test/runtests.jl index 4568f4b7..57d26314 100644 --- a/.vendor/SmithNormalForm/test/runtests.jl +++ b/.vendor/SmithNormalForm/test/runtests.jl @@ -7,12 +7,12 @@ using SmithNormalForm a = 12 b = 42 - s,t,g = SmithNormalForm.bezout(a,b) + g,s,t = SmithNormalForm.bezout(a,b) @test s*a + t*b == g g,s,t = gcdx(a,b) @test s*a + t*b == g - s,t,g = SmithNormalForm.bezout(b,a) + g,s,t = SmithNormalForm.bezout(b,a) @test s*b + t*a == g g,s,t = gcdx(b,a) @test s*b + t*a == g