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

Argument limited to Functions #224

Closed
matthieugomez opened this issue Jun 21, 2023 · 3 comments · Fixed by #228
Closed

Argument limited to Functions #224

matthieugomez opened this issue Jun 21, 2023 · 3 comments · Fixed by #228

Comments

@matthieugomez
Copy link

matthieugomez commented Jun 21, 2023

FiniteDifferences does not support objects that can be called without being a subtype of Function. It's a bit weird since Julia does not support multiple inheritances. Can the restriction <: Function be removed? If not it would be good to discuss the issue/workaround in the README.

using Interpolations
f = linear_interpolation(1:10, 1:10)
central_fdm(5, 1)(x -> f(x), 1.5)
# 1.000000000000018
central_fdm(5, 1)(f, 1.5)
#ERROR: MethodError: no method matching (::FiniteDifferences.AdaptedFiniteDifferenceMethod{5, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{7, 5}})(::Interpolations.Extrapolation{Float64, 1, ScaledInterpolation{Float64, 1, Interpolations.BSplineInterpolation{Float64, 1, Vector{Float64}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}}}, BSpline{Linear{Throw{OnGrid}}}, Tuple{UnitRange{Int64}}}, BSpline{Linear{Throw{OnGrid}}}, Throw{Nothing}}, ::Float64)
#Closest candidates are:
#  (::FiniteDifferences.AdaptedFiniteDifferenceMethod)(::TF, ::Real) where TF<:Function
#   @ FiniteDifferences ~/.julia/packages/FiniteDifferences/zZFW0/src/methods.jl:191
#  (::FiniteDifferences.AdaptedFiniteDifferenceMethod{P, Q})(::TF, ::Real, ::Real) where {P, Q, TF<:Function}
#   @ FiniteDifferences ~/.julia/packages/FiniteDifferences/zZFW0/src/methods.jl:238
@matthieugomez matthieugomez changed the title Support beyong Functions Argument limited to Functions Jun 21, 2023
@oxinabox
Copy link
Member

Easy work around is to wrap whatever you want to AD in a anon function.

I am trying to remember if there is a reason we don't just allow nonfunction subtypes.

@tpapp
Copy link
Contributor

tpapp commented Oct 27, 2023

The purpose of this restriction is not apparent to me either. Yes, the workaround is trivial, but slightly tedious for unit tests etc.

Would you consider accepting a PR removing the restriction it if it can be made to work?

@matthieugomez
Copy link
Author

Thanks!

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 a pull request may close this issue.

3 participants