Skip to content

Add support for floatmax(value) and friends - #746

Closed
mancellin wants to merge 1 commit into
JuliaDiff:masterfrom
mancellin:floatmax
Closed

mancellin wants to merge 1 commit into
JuliaDiff:masterfrom
mancellin:floatmax

Conversation

@mancellin

Copy link
Copy Markdown

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

codecov Bot commented Apr 11, 2025 •

Copy link
Copy Markdown

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.

@devmotion devmotion left a comment •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

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