-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathabstract_differential.jl
More file actions
42 lines (29 loc) · 1.35 KB
/
abstract_differential.jl
File metadata and controls
42 lines (29 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#####
##### `AbstractDifferential`
#####
"""
The subtypes of `AbstractDifferential` define a custom \"algebra\" for chain
rule evaluation that attempts to factor various features like complex derivative
support, broadcast fusion, zero-elision, etc. into nicely separated parts.
All subtypes of `AbstractDifferential` implement the following operations:
`+(a, b)`: linearly combine differential `a` and differential `b`
`*(a, b)`: multiply the differential `a` by the differential `b`
`Base.conj(x)`: complex conjugate of the differential `x`
`extern(x)`: convert `x` into an appropriate non-`AbstractDifferential` type for
use outside of `ChainContext`.
Valid arguments to these operations are `T` where `T<:AbstractDifferential`, or
where `T` has proper `+` and `*` implementations.
Additionally, all subtypes of `AbstractDifferential` support `Base.iterate` and
`Base.Broadcast.broadcastable(x)`.
"""
abstract type AbstractDifferential end
Base.:+(x::AbstractDifferential) = x
"""
extern(x)
Return `x` converted to an appropriate non-`AbstractDifferential` type, for use
with external packages that might not handle `AbstractDifferential` types.
Note that this function may return an alias (not necessarily a copy) to data
wrapped by `x`, such that mutating `extern(x)` might mutate `x` itself.
"""
@inline extern(x) = x
@inline Base.conj(x::AbstractDifferential) = x