API Documentation
ChainRulesOverloadGeneration.on_new_rule
— Methodon_new_rule(hook, frule | rrule)
Register a hook
function to run when new rules are defined. The hook receives a signature type-type as input, and generally will use eval
to define an overload of an AD system's overloaded type For example, using the signature type Tuple{typeof(+), Real, Real}
to make +(::DualNumber, ::DualNumber)
call the frule
for +
. A signature type tuple always has the form: Tuple{typeof(operation), typeof{pos_arg1}, typeof{pos_arg2}...}
, where pos_arg1
is the first positional argument.
The hooks are automatically run on new rules whenever a package is loaded. They can be manually triggered by refresh_rules
. When a hook is first registered with on_new_rule
it is run on all existing rules.
ChainRulesOverloadGeneration.refresh_rules
— Methodrefresh_rules()
refresh_rules(frule | rrule)
This triggers all on_new_rule
hooks to run on any newly defined rules. It is automatically run when ever a package is loaded. It can also be manually called to run it directly, for example if a rule was defined in the REPL or within the same file as the AD function.
Internal
ChainRulesOverloadGeneration.clear_new_rule_hooks!
— Functionclear_new_rule_hooks!(frule|rrule)
Clears all hooks that were registered with corresponding on_new_rule
. This is useful for while working interactively to define your rule generating hooks. If you previously wrong an incorrect hook, you can use this to get rid of the old one.
This absolutely should not be used in a package, as it will break any other AD system using the rule hooks that might happen to be loaded.