|
48 | 48 |
|
49 | 49 | @functor Chain
|
50 | 50 |
|
51 |
| -(c::Chain)(x) = applychain(c.layers, x) |
| 51 | +(c::Chain)(x) = _applychain(c.layers, x) |
52 | 52 |
|
53 | 53 | # Calculates the forward results of the complete chain provided as a `Tuple`, `AbstractVector`,
|
54 | 54 | # or a `NamedTuple` of layers with `x` as model input. Users are encouraged to call a chain
|
55 | 55 | # instead of using this function directly.
|
56 |
| -@generated function applychain(layers::Tuple{Vararg{<:Any,N}}, x) where {N} |
| 56 | +@generated function _applychain(layers::Tuple{Vararg{<:Any,N}}, x) where {N} |
57 | 57 | symbols = vcat(:x, [gensym() for _ in 1:N])
|
58 | 58 | calls = [:($(symbols[i+1]) = layers[$i]($(symbols[i]))) for i in 1:N]
|
59 | 59 | Expr(:block, calls...)
|
60 | 60 | end
|
61 | 61 |
|
62 |
| -applychain(layers::NamedTuple, x) = applychain(Tuple(layers), x) |
| 62 | +_applychain(layers::NamedTuple, x) = _applychain(Tuple(layers), x) |
63 | 63 |
|
64 |
| -function applychain(layers::AbstractVector, x) # type-unstable path, helps compile times |
| 64 | +function _applychain(layers::AbstractVector, x) # type-unstable path, helps compile times |
65 | 65 | for f in layers
|
66 | 66 | x = f(x)
|
67 | 67 | end
|
@@ -102,14 +102,14 @@ julia> activations(c, 1)
|
102 | 102 | (2, 4, 64)
|
103 | 103 | ```
|
104 | 104 | """
|
105 |
| -activations(c::Chain, input) = extraChain(Tuple(c.layers), input) |
| 105 | +activations(c::Chain, input) = _extraChain(Tuple(c.layers), input) |
106 | 106 |
|
107 | 107 | # Calculates the forward results of each layer provided in a `Tuple` with `x` as model input.
|
108 |
| -function extraChain(fs::Tuple, x) |
| 108 | +function _extraChain(fs::Tuple, x) |
109 | 109 | res = first(fs)(x)
|
110 |
| - return (res, extraChain(Base.tail(fs), res)...) |
| 110 | + return (res, _extraChain(Base.tail(fs), res)...) |
111 | 111 | end
|
112 |
| -extraChain(::Tuple{}, x) = () |
| 112 | +_extraChain(::Tuple{}, x) = () |
113 | 113 |
|
114 | 114 |
|
115 | 115 | """
|
|
0 commit comments