Skip to content

Commit d891f6d

Browse files
committed
macro docstring, incl. hcat(3.3)
1 parent ea5bc1c commit d891f6d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/layers/macro.jl

+10-9
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,35 @@ When you define a new layer, this tells Flux to explore inside it
1010
to see the parameters it trains, and also to move them to the GPU, change precision, etc.
1111
Like `@functor`, this assumes your struct has the default constructor, to enable re-building.
1212
13-
Some "keywords" allow control of the recursion.
13+
Some keywords allow you to limit this exploration, instead of visiting all `fieldnames(T)`.
14+
Note that it is never necessary to tell Flux to ignore non-array objects such as functions or sizes.
1415
* If some fields look like parameters but should not be trained,
15-
then `trainable` lets you specify fields to include, and ignore the rest.
16-
* You can likewise add restructions to Functors's `children` (although this is seldom a good idea).
16+
then `trainable` lets you specify which fields to include, while the rest are ignored.
17+
* You can likewise add restrictions to Functors's `children` (although this is seldom a good idea),
18+
equivalent to `@functor Struct (α,β)`. Any `trainable` limitation must then be a subset of `children`.
1719
18-
The defaults are `fieldnames(T)` for both. They must be subsets of this, and `trainable` must be a subset of `children`.
19-
20-
It also handles overloads of `show` for pretty printing.
20+
The macro also handles overloads of `show` for pretty printing.
2121
* By default, it adds methods to 3-arg `Base.show` to treat your layer much like `Dense` or `Conv`.
2222
* If your layer is a container, more like `Chain` or `Parallel`, then `:expand` makes `show` unfold its contents.
2323
* To disable all `show` overloads, there is an `:ignore` option too.
2424
25-
Note that re-running the macro with different options does not overwrite all methods, you will need to restart.
2625
(You probably still want to define 2-arg `show(io::IO, x::Layer)`, the macro does not touch this.)
2726
27+
Note that re-running the macro with different options may not overwrite all methods, you will need to restart.
28+
2829
# Example
2930
```jldoctest
3031
julia> struct Trio; a; b; c end
3132
32-
julia> tri = Trio(Dense([1.1 2.2], [0.0], tanh), Dense([3.3;;], false), Dropout(0.4))
33+
julia> tri = Trio(Dense([1.1 2.2], [0.0], tanh), Dense(hcat(3.3), false), Dropout(0.4))
3334
Trio(Dense(2 => 1, tanh), Dense(1 => 1; bias=false), Dropout(0.4))
3435
3536
julia> Flux.destructure(tri) # parameters are not yet visible to Flux
3637
(Bool[], Restructure(Trio, ..., 0))
3738
3839
julia> Flux.@layer :expand Trio
3940
40-
julia> Flux.destructure(tri) # now gpu, train!, etc will see inside too
41+
julia> Flux.destructure(tri) # now gpu, params, train!, etc will see inside too
4142
([1.1, 2.2, 0.0, 3.3], Restructure(Trio, ..., 4))
4243
4344
julia> tri # and layer is printed like Chain

0 commit comments

Comments
 (0)