Skip to content

ForwardDiff Overload Fixes #629

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jClugstor
Copy link
Member

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add any other context about the problem here.

@jClugstor
Copy link
Member Author

The overloads won't work with higher order derivatives or nested Duals. We would need a special way to handle higher order derivatives / maybe a general expression for x_p for higher order derivatives. So for now I just want to exclude nested Duals from going through this.
So I did this to try to exclude NestedDualLinearProblem from going through the overloads, but this is pretty restrictive. But if I do SingleDual{T, V, P} = Dual{T, V, P} where {T, V <:Number , P} then a NestedDualLinearProblem is also a NestedDualLinearProblem, which defeats the purpose. Essentially I want to make sure that if the value of the Dual is another Dual, go through the normal path and not the ForwardDiffExt path. @oscardssmith I wonder if you have any thoughts on how I could do that?

# Define type for non-nested dual numbers
const SingleDual{T, V, P} = Dual{T, V, P} where {T, V <:Float64 , P}

# Define type for nested dual numbers
const NestedDual{T, V, P} = Dual{T, V, P} where {T, V <: Dual, P}

const SingleDualLinearProblem = LinearProblem{
    <:Union{Number, <:AbstractArray, Nothing}, iip,
    <:Union{<:SingleDual, <:AbstractArray{<:SingleDual}},
    <:Union{<:SingleDual, <:AbstractArray{<:SingleDual}},
    <:Any
} where {iip}

const NestedDualLinearProblem = LinearProblem{
    <:Union{Number, <:AbstractArray, Nothing}, iip,
    <:Union{<:NestedDual, <:AbstractArray{<:NestedDual}},
    <:Union{<:NestedDual, <:AbstractArray{<:NestedDual}},
    <:Any
} where {iip}

const DualALinearProblem = LinearProblem{
    <:Union{Number, <:AbstractArray, Nothing},
    iip,
    <:Union{<:SingleDual, <:AbstractArray{<:SingleDual}},
    <:Union{Number, <:AbstractArray},
    <:Any
} where {iip}

const DualBLinearProblem = LinearProblem{
    <:Union{Number, <:AbstractArray, Nothing},
    iip,
    <:Union{Number, <:AbstractArray},
    <:Union{<:SingleDual, <:AbstractArray{<:SingleDual}},
    <:Any
} where {iip}

const DualAbstractLinearProblem = Union{
    SingleDualLinearProblem, DualALinearProblem, DualBLinearProblem}

@oscardssmith
Copy link
Member

I think making the higher order/nested cases work out shouldn't be too hard. Derivatives are a linear operator, so I think everything should compose nicely here.

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.

2 participants