-
Notifications
You must be signed in to change notification settings - Fork 64
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Right now we use debug mode (#136) with the special error type for addition of composites to primals failing, to give instructions on how to overload things to fix this.
But in julia 1.5 there is special functionality for adding hints for how to resolve errors build in by some magic:
JuliaLang/julia#35094
ChainRulesCore.jl/src/differentials/composite.jl
Lines 233 to 254 in 1be9bc4
| struct PrimalAdditionFailedException{P} <: Exception | |
| primal::P | |
| differential::Composite{P} | |
| original::Exception | |
| end | |
| function Base.showerror(io::IO, err::PrimalAdditionFailedException{P}) where {P} | |
| println(io, "Could not construct $P after addition.") | |
| println(io, "This probably means no default constructor is defined.") | |
| println(io, "Either define a default constructor") | |
| printstyled(io, "$P(", join(propertynames(err.differential), ", "), ")", color=:blue) | |
| println(io, "\nor overload") | |
| printstyled(io, | |
| "ChainRulesCore.construct(::Type{$P}, ::$(typeof(err.differential)))"; | |
| color=:blue | |
| ) | |
| println(io, "\nor overload") | |
| printstyled(io, "Base.:+(::$P, ::$(typeof(err.differential)))"; color=:blue) | |
| println(io, "\nOriginal Exception:") | |
| printstyled(io, err.original; color=:yellow) | |
| println(io) | |
| end |
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request