Skip to content

Commit 05a9a2d

Browse files
add other constructor + small changes
1 parent e2bc4e8 commit 05a9a2d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/layers/upsample.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
Upsample(mode = :nearest; [scale, size])
2+
Upsample(mode = :nearest; [scale, size])
3+
Upsample(scale, mode = :nearest)
34
45
An upsampling layer. One of two keywords must be given:
56
@@ -16,31 +17,33 @@ and corresponding NNlib's methods are:
1617
1718
```juliarepl
1819
julia> m = Upsample(scale = (2, 3))
19-
Upsample(:nearest, scale=(2, 3))
20+
Upsample(:nearest, scale = (2, 3))
2021
2122
julia> m(ones(2, 2, 1, 1)) |> size
2223
(4, 6, 1, 1)
2324
2425
julia> m = Upsample(:bilinear, size = (4, 5))
25-
Upsample(:bilinear, size=(4, 5))
26+
Upsample(:bilinear, size = (4, 5))
2627
2728
julia> m(ones(2, 2, 1, 1)) |> size
2829
(4, 5, 1, 1)
2930
"""
30-
struct Upsample{Mode,S,T}
31+
struct Upsample{mode, S, T}
3132
scale::S
3233
size::T
3334
end
3435

35-
function Upsample(mode = :nearest; scale = nothing, size = nothing)
36+
function Upsample(mode::Symbol = :nearest; scale = nothing, size = nothing)
3637
mode in [:nearest, :bilinear] ||
3738
throw(ArgumentError("mode=:$mode is not supported."))
38-
if ~((scale === nothing) (size === nothing))
39-
throw(ArgumentError("Either scale or size should be specified."))
39+
if !(isnothing(scale) isnothing(size))
40+
throw(ArgumentError("Either scale or size should be specified (but not both)."))
4041
end
4142
return Upsample{mode,typeof(scale),typeof(size)}(scale, size)
4243
end
4344

45+
Upsample(scale, mode::Symbol = :nearest) = Upsample(mode; scale)
46+
4447
(m::Upsample{:nearest})(x::AbstractArray) =
4548
NNlib.upsample_nearest(x, m.scale)
4649
function (m::Upsample{:nearest, Int})(x::AbstractArray{T, N}) where {T, N}

0 commit comments

Comments
 (0)