Skip to content

Commit 2423c1e

Browse files
committed
fix all doctests
1 parent f65d514 commit 2423c1e

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

docs/src/utilities.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To change the default on an applicable layer, pass the desired function with the
2828

2929
```jldoctest; setup = :(using Flux)
3030
julia> conv = Conv((3, 3), 1 => 8, relu; init=Flux.glorot_normal)
31-
Conv((3, 3), 1=>8, relu)
31+
Conv((3, 3), 1 => 8, relu) # 80 parameters
3232
```
3333

3434
```@docs

src/layers/basic.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ The weight matrix and/or the bias vector (of length `out`) may also be provided
8989
# Examples
9090
```jldoctest
9191
julia> d = Dense(5, 2)
92-
Dense(5, 2)
92+
Dense(5, 2) # 12 parameters
9393
9494
julia> d(rand(Float32, 5, 64)) |> size
9595
(2, 64)
@@ -98,7 +98,7 @@ julia> d(rand(Float32, 5, 1, 1, 64)) |> size # treated as three batch dimension
9898
(2, 1, 1, 64)
9999
100100
julia> d1 = Dense(ones(2, 5), false, tanh) # using provided weight matrix
101-
Dense(5, 2, tanh; bias=false)
101+
Dense(5, 2, tanh; bias=false) # 10 parameters
102102
103103
julia> d1(ones(5))
104104
2-element Vector{Float64}:
@@ -395,7 +395,11 @@ julia> size(model(rand(3)))
395395
(17,)
396396
397397
julia> model = Parallel(+, Dense(10, 2), Dense(5, 2))
398-
Parallel(+, Dense(10, 2), Dense(5, 2))
398+
Parallel(
399+
+,
400+
Dense(10, 2), # 22 parameters
401+
Dense(5, 2), # 12 parameters
402+
) # Total: 4 arrays, 34 parameters, 392 bytes
399403
400404
julia> size(model(rand(10), rand(5)))
401405
(2,)

src/layers/conv.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ See also [`ConvTranspose`](@ref), [`DepthwiseConv`](@ref), [`CrossCor`](@ref).
6767
julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of images
6868
6969
julia> lay = Conv((5,5), 3 => 7, relu; bias=false)
70-
Conv((5, 5), 3 => 7, relu) # 525 parameters
70+
Conv((5, 5), 3 => 7, relu, bias=false) # 525 parameters
7171
7272
julia> lay(xs) |> size
7373
(96, 96, 7, 50)
@@ -291,7 +291,7 @@ See also [`Conv`](@ref) for more detailed description of keywords.
291291
julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of 50 RGB images
292292
293293
julia> lay = DepthwiseConv((5,5), 3 => 6, relu; bias=false)
294-
DepthwiseConv((5, 5), 3 => 6, relu) # 150 parameters
294+
DepthwiseConv((5, 5), 3 => 6, relu, bias=false) # 150 parameters
295295
296296
julia> lay(xs) |> size
297297
(96, 96, 6, 50)
@@ -379,7 +379,7 @@ See also [`Conv`](@ref) for more detailed description of keywords.
379379
julia> xs = rand(Float32, 100, 100, 3, 50); # a batch of 50 RGB images
380380
381381
julia> lay = CrossCor((5,5), 3 => 6, relu; bias=false)
382-
CrossCor((5, 5), 3 => 6, relu) # 450 parameters
382+
CrossCor((5, 5), 3 => 6, relu, bias=false) # 450 parameters
383383
384384
julia> lay(xs) |> size
385385
(96, 96, 6, 50)
@@ -618,7 +618,7 @@ julia> xs = rand(Float32, 100, 100, 3, 50); # batch of 50 RGB images
618618
619619
julia> m = Chain(Conv((5, 5), 3 => 7, pad=SamePad()), MaxPool((5, 5), pad=SamePad()))
620620
Chain(
621-
Conv((5, 5), 3 => 7, pad=2), # 532 parameters
621+
Conv((5, 5), 3 => 7, pad=2), # 532 parameters
622622
MaxPool((5, 5), pad=2),
623623
)
624624
@@ -683,7 +683,7 @@ julia> xs = rand(Float32, 100, 100, 3, 50);
683683
684684
julia> m = Chain(Conv((5,5), 3 => 7), MeanPool((5,5), pad=SamePad()))
685685
Chain(
686-
Conv((5, 5), 3 => 7), # 532 parameters
686+
Conv((5, 5), 3 => 7), # 532 parameters
687687
MeanPool((5, 5), pad=2),
688688
)
689689

src/utils.jl

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ This function is mainly used by weight initializers, e.g., [`kaiming_normal`](@r
1313
# Examples
1414
1515
```jldoctest
16-
julia> layer = Dense(10, 20)
17-
Dense(10, 20)
16+
julia> layer = Dense(10, 20);
1817
1918
julia> Flux.nfan(size(layer.W))
2019
(10, 20)
2120
22-
julia> layer = Conv((3, 3), 2=>10)
23-
Conv((3, 3), 2=>10)
21+
julia> layer = Conv((3, 3), 2=>10);
2422
2523
julia> Flux.nfan(size(layer.weight))
2624
(18, 90)
@@ -506,7 +504,7 @@ julia> Flux.chunk(1:10, 3)
506504
9:10
507505
508506
julia> Flux.chunk(collect(1:10), 3)
509-
3-element Vector{SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{Int64}}, true}}:
507+
3-element Vector{SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{Int64}}, true}}:
510508
[1, 2, 3, 4]
511509
[5, 6, 7, 8]
512510
[9, 10]
@@ -720,19 +718,25 @@ over specific modules or subsets of the parameters
720718
# Examples
721719
722720
```jldoctest
723-
julia> m1 = Chain(Dense(28^2, 64), BatchNorm(64, relu))
724-
Chain(Dense(784, 64), BatchNorm(64, relu))
721+
julia> m1 = Chain(Dense(28^2, 64), BatchNorm(64, relu));
725722
726723
julia> m2 = Chain(m1, Dense(64, 10))
727-
Chain(Chain(Dense(784, 64), BatchNorm(64, relu)), Dense(64, 10))
724+
Chain(
725+
Chain(
726+
Dense(784, 64), # 50_240 parameters
727+
BatchNorm(64, relu), # 128 parameters, plus 128
728+
),
729+
Dense(64, 10), # 650 parameters
730+
) # Total: 6 trainable arrays, with 51_018 parameters
731+
# plus 2 non-trainable, 128 parameters, summarysize 200.312 KiB
728732
729733
julia> Flux.modules(m2)
730734
5-element Vector{Any}:
731-
Chain(Chain(Dense(784, 64), BatchNorm(64, relu)), Dense(64, 10))
732-
Chain(Dense(784, 64), BatchNorm(64, relu))
733-
Dense(784, 64)
734-
BatchNorm(64, relu)
735-
Dense(64, 10)
735+
Chain(Chain(Dense(784, 64), BatchNorm(64, relu)), Dense(64, 10)) # 51_018 parameters, plus 128 non-trainable
736+
Chain(Dense(784, 64), BatchNorm(64, relu)) # 50_368 parameters, plus 128 non-trainable
737+
Dense(784, 64) # 50_240 parameters
738+
BatchNorm(64, relu) # 128 parameters, plus 128 non-trainable
739+
Dense(64, 10) # 650 parameters
736740
737741
julia> L2(m) = sum(sum(abs2, l.weight) for l in Flux.modules(m) if l isa Dense)
738742
L2 (generic function with 1 method)
@@ -760,6 +764,7 @@ julia> loss() = rand();
760764
761765
julia> trigger = Flux.patience(() -> loss() < 1, 3);
762766
767+
763768
julia> Flux.@epochs 10 begin
764769
trigger() && break
765770
end
@@ -796,6 +801,7 @@ julia> loss = let l = 0
796801
797802
julia> es = Flux.early_stopping(loss, 3);
798803
804+
799805
julia> Flux.@epochs 10 begin
800806
es() && break
801807
end
@@ -836,6 +842,7 @@ julia> f = let v = 10
836842
837843
julia> trigger = Flux.plateau(f, 3; init_score=10, min_dist=18);
838844
845+
839846
julia> Flux.@epochs 10 begin
840847
trigger() && break
841848
end

0 commit comments

Comments
 (0)