From a335548729644661f9166b8999dcc09d9bd12438 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Thu, 9 Jan 2025 13:19:30 +0100 Subject: [PATCH 1/3] Fix method ambiguity error of `NaNMath.pow` --- src/methods.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/methods.jl b/src/methods.jl index 2baef6424..36492da0b 100644 --- a/src/methods.jl +++ b/src/methods.jl @@ -98,6 +98,9 @@ end @number_methods(BasicSymbolic{<:Number}, term(f, a), term(f, a, b), skipbasics) @number_methods(BasicSymbolic{<:LiteralReal}, term(f, a), term(f, a, b), onlybasics) +# Fix method ambiguity issue in NaNMath >= 1.0.2 +NaNMath.pow(x::BasicSymbolic{<:Number}, y::Integer) = x^y + for f in vcat(diadic, [+, -, *, \, /, ^]) @eval promote_symtype(::$(typeof(f)), T::Type{<:Number}, From 0726f51424eb4d75900b449b074055213f793dad Mon Sep 17 00:00:00 2001 From: David Widmann Date: Fri, 10 Jan 2025 12:25:27 +0100 Subject: [PATCH 2/3] Change `@number_methods` instead --- src/methods.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/methods.jl b/src/methods.jl index 36492da0b..ddfc919ce 100644 --- a/src/methods.jl +++ b/src/methods.jl @@ -77,6 +77,11 @@ function number_methods(T, rhs1, rhs2, options=nothing) end push!(exprs, expr) + + # Fix method ambiguity error on NaNMath >= 1.0.2 and promotion of `Integer`s on NaNMath < 1.0.2 + if f === NaNMath.pow + push!(exprs, :($(NaNMath.pow)(a::$T, b::Integer) = ($assert_like($(NaNMath.pow), Number, a); $term($(^), a, b)))) + end end for f in (skip_basics ? monadic : only_basics ? basic_monadic : vcat(basic_monadic, monadic)) @@ -98,9 +103,6 @@ end @number_methods(BasicSymbolic{<:Number}, term(f, a), term(f, a, b), skipbasics) @number_methods(BasicSymbolic{<:LiteralReal}, term(f, a), term(f, a, b), onlybasics) -# Fix method ambiguity issue in NaNMath >= 1.0.2 -NaNMath.pow(x::BasicSymbolic{<:Number}, y::Integer) = x^y - for f in vcat(diadic, [+, -, *, \, /, ^]) @eval promote_symtype(::$(typeof(f)), T::Type{<:Number}, From 82d8e3e0e19362d7acb3927f551e692c0addc96b Mon Sep 17 00:00:00 2001 From: David Widmann Date: Fri, 10 Jan 2025 12:31:54 +0100 Subject: [PATCH 3/3] More consistent code --- src/methods.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/methods.jl b/src/methods.jl index ddfc919ce..ab8cfd66a 100644 --- a/src/methods.jl +++ b/src/methods.jl @@ -80,7 +80,7 @@ function number_methods(T, rhs1, rhs2, options=nothing) # Fix method ambiguity error on NaNMath >= 1.0.2 and promotion of `Integer`s on NaNMath < 1.0.2 if f === NaNMath.pow - push!(exprs, :($(NaNMath.pow)(a::$T, b::Integer) = ($assert_like($(NaNMath.pow), Number, a); $term($(^), a, b)))) + push!(exprs, :((f::$(typeof(f)))(a::$T, b::Integer) = ($assert_like(f, Number, a); $term($(^), a, b)))) end end