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

Fix method ambiguity error of NaNMath.pow #690

Merged
merged 3 commits into from
Jan 13, 2025

Conversation

devmotion
Copy link
Contributor

NaNMath 1.0.2 introduced a method ambiguity error.

@devmotion
Copy link
Contributor Author

Hmm seems not sufficient...

src/methods.jl Outdated
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NaNMath.pow(x::BasicSymbolic{<:Number}, y::Integer) = x^y
NaNMath.pow(x::BasicSymbolic{<:Number}, y::Integer) = maketerm(typeof(x), NaNMath.pow, [x, y], metadata(x))

Copy link
Contributor Author

@devmotion devmotion Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid NaNMath in that case in NaNMath < 1.0.2 and on NaNMath >= 1.0.2 an Integer as second argument falls back to ^ anyway. So I think using ^ is the better and safer approach, regardless of the NaNMath version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then can we add this to @number_methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did but I guess incorrectly. The original error is gone but it seems it causes https://github.com/JuliaSymbolics/SymbolicUtils.jl/actions/runs/12708708876/job/35426212172?pr=690#step:6:885.

@AayushSabharwal
Copy link
Contributor

In fact, this should instead be a change to @number_methods which adds a NaNMath.pow(::T, ::Integer)

@AayushSabharwal
Copy link
Contributor

Actually, never mind 😅 Symbolics is the only one with the ambiguity, right? Because Num <: Number. Adding a method here doesn't help. We instead need NaNMath.pow(x::Num, y::Integer) = wrap(NaNMath.pow(unwrap(x), y)) in Symbolics

@AayushSabharwal
Copy link
Contributor

@AayushSabharwal
Copy link
Contributor

I think a couple of the tests need to be updated

@ChrisRackauckas ChrisRackauckas merged commit bf23a1d into JuliaSymbolics:master Jan 13, 2025
6 of 10 checks passed
@devmotion devmotion deleted the patch-1 branch January 13, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants