From 67689fac1364ebbbd858cd94bce9cf7d89cbe165 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Tue, 17 Sep 2019 22:54:40 +0100 Subject: [PATCH 1/2] Rename `DNE` -> `DoesNotExist` --- src/ChainRulesCore.jl | 2 +- src/differential_arithmetic.jl | 18 +++++++++--------- src/differentials.jl | 16 ++++++++-------- test/differentials.jl | 2 +- test/runtests.jl | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/ChainRulesCore.jl b/src/ChainRulesCore.jl index c5f1622e3..331c4ae5e 100644 --- a/src/ChainRulesCore.jl +++ b/src/ChainRulesCore.jl @@ -5,7 +5,7 @@ export frule, rrule export wirtinger_conjugate, wirtinger_primal, refine_differential export @scalar_rule, @thunk export extern, cast, store! -export Wirtinger, Zero, One, DNE, Thunk, InplaceableThunk +export Wirtinger, Zero, One, DoesNotExist, Thunk, InplaceableThunk export NO_FIELDS include("differentials.jl") diff --git a/src/differential_arithmetic.jl b/src/differential_arithmetic.jl index 0dd636b18..eb06b9bac 100644 --- a/src/differential_arithmetic.jl +++ b/src/differential_arithmetic.jl @@ -7,7 +7,7 @@ subtypes, as we know the full set that might be encountered. Thus we can avoid any ambiguities. Notice: - The precidence goes: (:Wirtinger, :Zero, :DNE, :One, :AbstractThunk, :Any) + The precidence goes: (:Wirtinger, :Zero, :DoesNotExist, :One, :AbstractThunk, :Any) Thus each of the @eval loops creating definitions of + and * defines the combination this type with all types of lower precidence. This means each eval loops is 1 item smaller than the previous. @@ -36,7 +36,7 @@ function Base.:+(a::Wirtinger, b::Wirtinger) return Wirtinger(+(a.primal, b.primal), a.conjugate + b.conjugate) end -for T in (:Zero, :DNE, :One, :AbstractThunk, :Any) +for T in (:Zero, :DoesNotExist, :One, :AbstractThunk, :Any) @eval Base.:+(a::Wirtinger, b::$T) = a + Wirtinger(b, Zero()) @eval Base.:+(a::$T, b::Wirtinger) = Wirtinger(a, Zero()) + b @@ -47,7 +47,7 @@ end Base.:+(::Zero, b::Zero) = Zero() Base.:*(::Zero, ::Zero) = Zero() -for T in (:DNE, :One, :AbstractThunk, :Any) +for T in (:DoesNotExist, :One, :AbstractThunk, :Any) @eval Base.:+(::Zero, b::$T) = b @eval Base.:+(a::$T, ::Zero) = a @@ -56,14 +56,14 @@ for T in (:DNE, :One, :AbstractThunk, :Any) end -Base.:+(::DNE, ::DNE) = DNE() -Base.:*(::DNE, ::DNE) = DNE() +Base.:+(::DoesNotExist, ::DoesNotExist) = DoesNotExist() +Base.:*(::DoesNotExist, ::DoesNotExist) = DoesNotExist() for T in (:One, :AbstractThunk, :Any) - @eval Base.:+(::DNE, b::$T) = b - @eval Base.:+(a::$T, ::DNE) = a + @eval Base.:+(::DoesNotExist, b::$T) = b + @eval Base.:+(a::$T, ::DoesNotExist) = a - @eval Base.:*(::DNE, ::$T) = DNE() - @eval Base.:*(::$T, ::DNE) = DNE() + @eval Base.:*(::DoesNotExist, ::$T) = DoesNotExist() + @eval Base.:*(::$T, ::DoesNotExist) = DoesNotExist() end diff --git a/src/differentials.jl b/src/differentials.jl index ca1d91d8a..640ee02bb 100644 --- a/src/differentials.jl +++ b/src/differentials.jl @@ -106,26 +106,26 @@ Base.iterate(::Zero, ::Any) = nothing ##### -##### `DNE` +##### `DoesNotExist` ##### """ - DNE() + DoesNotExist() This differential indicates that the derivative Does Not Exist (D.N.E). This is not the cast that it is not implemented, but rather that it mathematically is not defined. """ -struct DNE <: AbstractDifferential end +struct DoesNotExist <: AbstractDifferential end -function extern(x::DNE) +function extern(x::DoesNotExist) throw(ArgumentError("Derivative does not exit. Cannot be converted to an external type.")) end -Base.Broadcast.broadcastable(::DNE) = Ref(DNE()) +Base.Broadcast.broadcastable(::DoesNotExist) = Ref(DoesNotExist()) -Base.iterate(x::DNE) = (x, nothing) -Base.iterate(::DNE, ::Any) = nothing +Base.iterate(x::DoesNotExist) = (x, nothing) +Base.iterate(::DoesNotExist, ::Any) = nothing ##### ##### `One` @@ -270,7 +270,7 @@ Constant for the reverse-mode derivative with respect to a structure that has no The most notable use for this is for the reverse-mode derivative with respect to the function itself, when that function is not a closure. """ -const NO_FIELDS = DNE() +const NO_FIELDS = DoesNotExist() """ refine_differential(𝒟::Type, der) diff --git a/test/differentials.jl b/test/differentials.jl index 51d80c596..6ddad9b4f 100644 --- a/test/differentials.jl +++ b/test/differentials.jl @@ -104,7 +104,7 @@ @test refine_differential(typeof([1.2]), Wirtinger(2,2)) == 4 # For most differentials, in most domains, this does nothing - for der in (DNE(), @thunk(23), @thunk(Wirtinger(2,2)), [1 2], One(), Zero(), 0.0) + for der in (DoesNotExist(), @thunk(23), @thunk(Wirtinger(2,2)), [1 2], One(), Zero(), 0.0) for 𝒟 in typeof.((1.0 + 1im, [1.0 + 1im], 1.2, [1.2])) @test refine_differential(𝒟, der) === der end diff --git a/test/runtests.jl b/test/runtests.jl index e0282a66b..bc3c9cde1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,7 @@ using ChainRulesCore using LinearAlgebra: Diagonal using ChainRulesCore: extern, accumulate, accumulate!, store!, @scalar_rule, Wirtinger, wirtinger_primal, wirtinger_conjugate, - Zero, One, DNE, Thunk + Zero, One, DoesNotExist, Thunk using Base.Broadcast: broadcastable @testset "ChainRulesCore" begin From efb9c19c8a98dedb94a09bf119261dde5fc238d3 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Fri, 25 Oct 2019 18:53:44 +0100 Subject: [PATCH 2/2] Deprecate DNE binding --- src/ChainRulesCore.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ChainRulesCore.jl b/src/ChainRulesCore.jl index 331c4ae5e..07ce7a376 100644 --- a/src/ChainRulesCore.jl +++ b/src/ChainRulesCore.jl @@ -13,4 +13,7 @@ include("differential_arithmetic.jl") include("operations.jl") include("rules.jl") include("rule_definition_tools.jl") + +Base.@deprecate_binding DNE DoesNotExist + end # module