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

Add NotImplemented and NotImplementedRule #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/differentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ This way, we don't need to implement promotion/conversion rules between subtypes
of `AbstractDifferential` to resolve potential ambiguities.
=#

const PRECEDENCE_LIST = [:wirtinger, :casted, :zero, :dne, :one, :thunk, :fallback]
const PRECEDENCE_LIST = [:wirtinger, :casted, :zero, :dne, :notimplemented, :one,
:thunk, :fallback]

global defs = Expr(:block)

Expand Down Expand Up @@ -227,6 +228,33 @@ mul_dne(::DNE, ::DNE) = DNE()
mul_dne(::DNE, ::Any) = DNE()
mul_dne(::Any, ::DNE) = DNE()

#####
##### `NotImplemented`
#####

"""
NotImplemented <: AbstractDifferential

A differential type which behaves similar to [`DNE`](@ref) but instead signifies that
the actual differential is not implemented in ChainRules, not that it does not exist.
Copy link
Member

Choose a reason for hiding this comment

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

Can there be a "not yet" added here?
Maybe even a "PRs to remove not implemented rules are welcome"

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea.

"""
struct NotImplemented <: AbstractDifferential end

extern(::NotImplemented) = error("`NotImplemented` cannot be converted to an external type.")

Base.Broadcast.broadcastable(::NotImplemented) = Ref(NotImplemented())

Base.iterate(x::NotImplemented) = (x, nothing)
Base.iterate(x::NotImplemented, ::Any) = nothing

add_notimplemented(::NotImplemented, ::NotImplemented) = NotImplemented()
add_notimplemented(::NotImplemented, b) = b
add_notimplemented(a, ::NotImplemented) = a

mul_notimplemented(::NotImplemented, ::NotImplemented) = NotImplemented()
mul_notimplemented(::NotImplemented, ::Any) = NotImplemented()
mul_notimplemented(::Any, ::NotImplemented) = NotImplemented()

#####
##### `One`
#####
Expand Down
14 changes: 14 additions & 0 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ struct DNERule <: AbstractRule end

DNERule(args...) = DNE()

#####
##### `NotImplementedRule`
#####

"""
NotImplementedRule <: AbstractRule

Rule indicating that a particular derivative is not implemented by ChainRules.
Copy link
Member

Choose a reason for hiding this comment

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

As with @oxinabox 's comment above, I would like to see this expanded slightly to say more about what a NotImplementedRule does mean. Some context would be helpful e.g.

"""
Rule indicating that a particular derivative is not yet implemented by ChainRules. Different from [`DNERule`](@ref) in that this rule does not imply non-differentiability, but rather that no one has implemented it yet.
"""

Note that this does not imply nondifferentiability; for that, use [`DNERule`](@ref).
"""
struct NotImplementedRule <: AbstractRule end

NotImplementedRule(args...) = NotImplemented()

#####
##### `WirtingerRule`
#####
Expand Down