Skip to content

Conversation

mancellin
Copy link

Fix JuliaMath/SpecialFunctions.jl#475

The SpecialFunction expint is using floatmax on a value and thus the following currently fails:

ForwardDiff.derivative(x -> expint(im*x), 1.0)

I believe it makes sense to support both floatmax(::T) and floatmax(::Type{T}) here since Base implements both.

@codecov
Copy link

codecov bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.99%. Comparing base (c310fb5) to head (78f230f).
Report is 21 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #746      +/-   ##
==========================================
- Coverage   89.57%   86.99%   -2.59%     
==========================================
  Files          11       10       -1     
  Lines         969      961       -8     
==========================================
- Hits          868      836      -32     
- Misses        101      125      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

I just checked, and the docstring of typemin, typemax, floatmin, and floatmax only documents that these function can be called with types. A non-Type argument does not seem to be documented, so maybe it's not intended to be used with values? For comparison, the docstring for eps documents both the version with values and types.

The Julia docs even discourage the definition of functions for both value and type arguments: https://docs.julialang.org/en/v1/manual/style-guide/#Avoid-confusion-about-whether-something-is-an-instance-or-a-type

Given the documentation of these functions, I'd think the better solution would be to change https://github.com/JuliaMath/SpecialFunctions.jl/blob/c400278f3b358aea817e03bfdf9e23c3c08557e5/src/expint.jl#L169 to scale = sqrt(floatmax(typeof(real(A)))).

@mancellin
Copy link
Author

Given the documentation of these functions, I'd think the better solution would be to change SpecialFunctions

I'm fine with both approaches.

@ararslan suggested in JuliaMath/SpecialFunctions.jl#475 to implement it in ForwardDiff, since other might be using the undocumented behavior from Base.

@devmotion
Copy link
Member

My feeling is that it would be preferable if it would be documented that this function is expected to work on values before adding these definitions in ForwardDiff.

@devmotion
Copy link
Member

Closed in favour of JuliaMath/SpecialFunctions.jl#494.

@devmotion devmotion closed this Apr 14, 2025
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.

Use of expint with ForwardDiff

2 participants