From 332b103201c801b1a49654dd4e460b34cd393c89 Mon Sep 17 00:00:00 2001 From: Herman Sletmoen Date: Thu, 7 Mar 2024 19:35:46 +0100 Subject: [PATCH 1/6] Make promote_operation work for division --- src/interface.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index e7c95c5..654404e 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -33,16 +33,16 @@ _instantiate(::Type{S}) where {S<:Irrational} = S() _instantiate_zero(::Type{S}) where {S<:AbstractIrrational} = _instantiate(S) _instantiate_oneunit(::Type{S}) where {S<:AbstractIrrational} = _instantiate(S) +# Julia v1.0.x has trouble with inference with the `Vararg` method, see +# https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373 function promote_operation_fallback( - ::typeof(/), + op::Union{typeof(/), typeof(//), typeof(÷), typeof(%)}, ::Type{S}, ::Type{T}, ) where {S,T} - return typeof(_instantiate_zero(S) / _instantiate_oneunit(T)) + return typeof(op(_instantiate_zero(S), _instantiate_oneunit(T))) end -# Julia v1.0.x has trouble with inference with the `Vararg` method, see -# https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373 function promote_operation_fallback( op::F, ::Type{S}, From c52f862819512b6f699b4a0bb0f593c824aed2ee Mon Sep 17 00:00:00 2001 From: Herman Sletmoen Date: Wed, 20 Mar 2024 20:23:05 +0100 Subject: [PATCH 2/6] Just update div --- src/interface.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface.jl b/src/interface.jl index 654404e..688c683 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -36,7 +36,7 @@ _instantiate_oneunit(::Type{S}) where {S<:AbstractIrrational} = _instantiate(S) # Julia v1.0.x has trouble with inference with the `Vararg` method, see # https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373 function promote_operation_fallback( - op::Union{typeof(/), typeof(//), typeof(÷), typeof(%)}, + op::Union{typeof(/), typeof(div)}, ::Type{S}, ::Type{T}, ) where {S,T} From 807667169ecda8c636420e0652222ae051704ea3 Mon Sep 17 00:00:00 2001 From: Herman Sletmoen Date: Thu, 21 Mar 2024 17:53:02 +0100 Subject: [PATCH 3/6] Format code Co-authored-by: Oscar Dowson --- src/interface.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface.jl b/src/interface.jl index 688c683..74f9490 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -36,7 +36,7 @@ _instantiate_oneunit(::Type{S}) where {S<:AbstractIrrational} = _instantiate(S) # Julia v1.0.x has trouble with inference with the `Vararg` method, see # https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373 function promote_operation_fallback( - op::Union{typeof(/), typeof(div)}, + op::Union{typeof(/),typeof(div)}, ::Type{S}, ::Type{T}, ) where {S,T} From ddfef2013acf1b0434544bd0ab9d1a526da4a850 Mon Sep 17 00:00:00 2001 From: Herman Sletmoen Date: Thu, 21 Mar 2024 18:55:27 +0100 Subject: [PATCH 4/6] Test that mutability runs with no error --- test/interface.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/interface.jl b/test/interface.jl index 489a567..f193697 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -178,3 +178,11 @@ end @test MA.operate_to!!(T(6), abs, T(7)) == 7 @test MA.operate_to!!(T(6), abs, T(-7)) == 7 end + +@testset "Error-free mutability (issue #240)" begin + for op in (+, -, *, /, div) + for T in (Float64, BigFloat, Int, BigInt, Rational{Int}, Rational{BigInt}) + @test_nowarn MA.mutability(T, op, T, T) # should run without error + end + end +end \ No newline at end of file From 6f3f3cf5ac169432665487f17e6ac2711c7bfae3 Mon Sep 17 00:00:00 2001 From: Herman Sletmoen Date: Thu, 21 Mar 2024 21:05:01 +0100 Subject: [PATCH 5/6] Format code Co-authored-by: Oscar Dowson --- test/interface.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/interface.jl b/test/interface.jl index f193697..5638dc2 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -185,4 +185,4 @@ end @test_nowarn MA.mutability(T, op, T, T) # should run without error end end -end \ No newline at end of file +end From d2c834135fcdf58202318da2869e60129308b319 Mon Sep 17 00:00:00 2001 From: Herman Sletmoen Date: Thu, 21 Mar 2024 21:36:32 +0100 Subject: [PATCH 6/6] Format code --- test/interface.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/interface.jl b/test/interface.jl index 5638dc2..aed08ec 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -181,7 +181,8 @@ end @testset "Error-free mutability (issue #240)" begin for op in (+, -, *, /, div) - for T in (Float64, BigFloat, Int, BigInt, Rational{Int}, Rational{BigInt}) + for T in + (Float64, BigFloat, Int, BigInt, Rational{Int}, Rational{BigInt}) @test_nowarn MA.mutability(T, op, T, T) # should run without error end end