|
1 | | -## Traits |
2 | | - |
3 | | -for trait in ( |
4 | | - :check_available, |
5 | | - :twoarg_support, |
6 | | - :pushforward_performance, |
7 | | - :pullback_performance, |
8 | | - :hvp_mode, |
9 | | -) |
10 | | - @eval $trait(backend::AutoSparse) = $trait(dense_ad(backend)) |
11 | | -end |
12 | | - |
13 | | -## Operators |
14 | | - |
15 | | -for op in (:pushforward, :pullback, :hvp) |
16 | | - op! = Symbol(op, "!") |
17 | | - valop = Symbol("value_and_", op) |
18 | | - valop! = Symbol("value_and_", op, "!") |
19 | | - prep = Symbol("prepare_", op) |
20 | | - prepsame = Symbol("prepare_", op, "_same_point") |
21 | | - E = if op == :pushforward |
22 | | - :PushforwardExtras |
23 | | - elseif op == :pullback |
24 | | - :PullbackExtras |
25 | | - elseif op == :hvp |
26 | | - :HVPExtras |
27 | | - end |
28 | | - |
29 | | - ## One argument |
30 | | - @eval begin |
31 | | - $prep(f::F, ba::AutoSparse, x, v) where {F} = $prep(f, dense_ad(ba), x, v) |
32 | | - $prepsame(f::F, ba::AutoSparse, x, v) where {F} = $prepsame(f, dense_ad(ba), x, v) |
33 | | - $prepsame(f::F, ba::AutoSparse, x, v, ex::$E) where {F} = |
34 | | - $prepsame(f, dense_ad(ba), x, v, ex) |
35 | | - $op(f::F, ba::AutoSparse, x, v, ex::$E=$prep(f, ba, x, v)) where {F} = |
36 | | - $op(f, dense_ad(ba), x, v, ex) |
37 | | - $valop(f::F, ba::AutoSparse, x, v, ex::$E=$prep(f, ba, x, v)) where {F} = |
38 | | - $valop(f, dense_ad(ba), x, v, ex) |
39 | | - $op!(f::F, res, ba::AutoSparse, x, v, ex::$E=$prep(f, ba, x, v)) where {F} = |
40 | | - $op!(f, res, dense_ad(ba), x, v, ex) |
41 | | - $valop!(f::F, res, ba::AutoSparse, x, v, ex::$E=$prep(f, ba, x, v)) where {F} = |
42 | | - $valop!(f, res, dense_ad(ba), x, v, ex) |
43 | | - end |
44 | | - |
45 | | - ## Two arguments |
46 | | - @eval begin |
47 | | - $prep(f!::F, y, ba::AutoSparse, x, v) where {F} = $prep(f!, y, dense_ad(ba), x, v) |
48 | | - $prepsame(f!::F, y, ba::AutoSparse, x, v) where {F} = |
49 | | - $prepsame(f!, y, dense_ad(ba), x, v) |
50 | | - $prepsame(f!::F, y, ba::AutoSparse, x, v, ex::$E) where {F} = |
51 | | - $prepsame(f!, y, dense_ad(ba), x, v, ex) |
52 | | - $op(f!::F, y, ba::AutoSparse, x, v, ex::$E=$prep(f!, y, ba, x, v)) where {F} = |
53 | | - $op(f!, y, dense_ad(ba), x, v, ex) |
54 | | - $valop(f!::F, y, ba::AutoSparse, x, v, ex::$E=$prep(f!, y, ba, x, v)) where {F} = |
55 | | - $valop(f!, y, dense_ad(ba), x, v, ex) |
56 | | - $op!(f!::F, y, res, ba::AutoSparse, x, v, ex::$E=$prep(f!, y, ba, x, v)) where {F} = |
57 | | - $op!(f!, y, res, dense_ad(ba), x, v, ex) |
58 | | - $valop!( |
59 | | - f!::F, y, res, ba::AutoSparse, x, v, ex::$E=$prep(f!, y, ba, x, v) |
60 | | - ) where {F} = $valop!(f!, y, res, dense_ad(ba), x, v, ex) |
61 | | - end |
62 | | -end |
63 | | - |
64 | | -for op in (:derivative, :gradient, :second_derivative) |
65 | | - op! = Symbol(op, "!") |
66 | | - valop = Symbol("value_and_", op) |
67 | | - valop! = Symbol("value_and_", op, "!") |
68 | | - prep = Symbol("prepare_", op) |
69 | | - E = if op == :derivative |
70 | | - :DerivativeExtras |
71 | | - elseif op == :gradient |
72 | | - :GradientExtras |
73 | | - elseif op == :second_derivative |
74 | | - :SecondDerivativeExtras |
75 | | - end |
76 | | - |
77 | | - ## One argument |
78 | | - @eval begin |
79 | | - $prep(f::F, ba::AutoSparse, x) where {F} = $prep(f, dense_ad(ba), x) |
80 | | - $op(f::F, ba::AutoSparse, x, ex::$E=$prep(f, ba, x)) where {F} = |
81 | | - $op(f, dense_ad(ba), x, ex) |
82 | | - $valop(f::F, ba::AutoSparse, x, ex::$E=$prep(f, ba, x)) where {F} = |
83 | | - $valop(f, dense_ad(ba), x, ex) |
84 | | - $op!(f::F, res, ba::AutoSparse, x, ex::$E=$prep(f, ba, x)) where {F} = |
85 | | - $op!(f, res, dense_ad(ba), x, ex) |
86 | | - $valop!(f::F, res, ba::AutoSparse, x, ex::$E=$prep(f, ba, x)) where {F} = |
87 | | - $valop!(f, res, dense_ad(ba), x, ex) |
88 | | - end |
89 | | - |
90 | | - ## Two arguments |
91 | | - if op in (:derivative,) |
92 | | - @eval begin |
93 | | - $prep(f!::F, y, ba::AutoSparse, x) where {F} = $prep(f!, y, dense_ad(ba), x) |
94 | | - $op(f!::F, y, ba::AutoSparse, x, ex::$E=$prep(f!, y, ba, x)) where {F} = |
95 | | - $op(f!, y, dense_ad(ba), x, ex) |
96 | | - $valop(f!::F, y, ba::AutoSparse, x, ex::$E=$prep(f!, y, ba, x)) where {F} = |
97 | | - $valop(f!, y, dense_ad(ba), x, ex) |
98 | | - $op!(f!::F, y, res, ba::AutoSparse, x, ex::$E=$prep(f!, y, ba, x)) where {F} = |
99 | | - $op!(f!, y, res, dense_ad(ba), x, ex) |
100 | | - $valop!( |
101 | | - f!::F, y, res, ba::AutoSparse, x, ex::$E=$prep(f!, y, ba, x) |
102 | | - ) where {F} = $valop!(f!, y, res, dense_ad(ba), x, ex) |
103 | | - end |
104 | | - end |
105 | | -end |
| 1 | +check_available(backend::AutoSparse) = check_available(dense_ad(backend)) |
| 2 | +twoarg_support(backend::AutoSparse) = twoarg_support(dense_ad(backend)) |
| 3 | +pushforward_performance(backend::AutoSparse) = pushforward_performance(dense_ad(backend)) |
| 4 | +pullback_performance(backend::AutoSparse) = pullback_performance(dense_ad(backend)) |
| 5 | +hvp_mode(backend::AutoSparse{<:SecondOrder}) = hvp_mode(dense_ad(backend)) |
0 commit comments