From d22683f33ccb60c2754310d500c4ae5eb36e5ccd Mon Sep 17 00:00:00 2001 From: Michael Abbott Date: Sun, 17 Jan 2021 20:43:40 +0100 Subject: [PATCH 1/9] add upsample_nearest function --- src/upsample.jl | 62 ++++++++++++++++++++++++++++++++++++++++++++++-- test/upsample.jl | 12 ++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/upsample.jl b/src/upsample.jl index 860e8441b..876c4b31c 100644 --- a/src/upsample.jl +++ b/src/upsample.jl @@ -1,7 +1,65 @@ -export upsample_bilinear, ∇upsample_bilinear, pixel_shuffle +export upsample_nearest, ∇upsample_nearest, + upsample_bilinear, ∇upsample_bilinear, + pixel_shuffle """ - upsample_bilinear(x::AbstractArray{<:Number,4}, k::NTuple{2,Int}) + upsample_nearest(x::AbstractArray{T,N}, scale) + +Upsamples by an integer multiple. For `scale::Integer`, this applies to the first +`N-2` dimensions of `x` (the remainder assumed to be channel & batch dimensions). +For `scale::Tuple`, the first `length(scale)` dimensions are altered. + +See also [`upsample_bilinear`](@ref), for two dimensions of an `N=4` array. + +# Example +```jldoctest +julia> upsample_nearest([1 2 3; 4 5 6], (2,3)) +4×9 Matrix{Int64}: + 1 1 1 2 2 2 3 3 3 + 1 1 1 2 2 2 3 3 3 + 4 4 4 5 5 5 6 6 6 + 4 4 4 5 5 5 6 6 6 +``` +""" +upsample_nearest(x::AbstractArray, s::Integer) = upsample_nearest(x, ntuple(_->s, ndims(x)-2)) + +function upsample_nearest(x::AbstractArray{T,N}, scales::NTuple{S, <:Integer}) where {T,N,S} + S in 1:N || throw(ArgumentError("can't upsample ndims(x)=$N with scale=$scales")) + outsize = ntuple(d -> d<=S ? scales[d] * size(x,d) : size(x,d), N) + out = similar(x, T, outsize) + writesize = ntuple(N+S) do d + d > 2S && return size(x, d-S) + isodd(d) ? scales[cld(d,2)] : size(x, cld(d,2)) + end + readsize = ntuple(N+S) do d + d > 2S && return size(x, d-S) + isodd(d) ? 1 : size(x, cld(d,2)) + end + reshape(out, writesize) .= reshape(x, readsize) + out +end + +function ∇upsample_nearest(x::AbstractArray{T,N}, scales::NTuple{S, <:Integer}) where {T,N,S} + outsize = ntuple(N) do d + d > S && return size(x,d) + rem(size(x,d), scales[d]) == 0 || throw(ArgumentError("expected input array evenly divisible by scale=$scales, got size(x)=$(size(x))")) + div(size(x,d), scales[d]) + end + tempsize = ntuple(N+S) do d + d > 2S && return size(x, d-S) + s = scales[cld(d,2)] + isodd(d) ? s : div(size(x, cld(d,2)),s) + end + mid = sum(reshape(x, tempsize), dims=ntuple(d -> 2d-1, S)) + reshape(mid, outsize) +end + +function ChainRulesCore.rrule(::typeof(upsample_nearest), x::AbstractArray, s::Tuple) + Ω = upsample_nearest(x, s) + upsample_nearest_pullback(Δ) = (NO_FIELDS, ∇upsample_nearest(Δ, k), DoesNotExist()) + return Ω, upsample_nearest_pullback +end + Upsamples the first 2 dimensions of the array `x` by the upsample factors stored in `k`, using bilinear interpolation. diff --git a/test/upsample.jl b/test/upsample.jl index 6d07a1344..8b5cb5ba7 100644 --- a/test/upsample.jl +++ b/test/upsample.jl @@ -1,3 +1,15 @@ +@testset "upsample_nearest" begin + x = reshape(Float32[1. 2.; 3. 4.], (2,2,1,1)) + @test upsample_nearest(x, 3)[1,:] == [1,1,1, 2,2,2] + + y = upsample_nearest(x, (2,3)) + @test size(y) == (4,6,1,1) + ∇upsample_nearest(y, (2,3)) == [6 12; 18 24] + + @test_throws ArgumentError ∇upsample_nearest(y, (2,4)) + @test_throws ArgumentError upsample_nearest(x, (1,2,3,4,5)) +end + @testset "upsample_bilinear 2d" begin x = reshape(Float32[1. 2.; 3. 4.], (2,2,1,1)) y_true = [1//1 5//4 7//4 2//1; From bfa9dc11956e426cafa0ccb713eadb20a3829a87 Mon Sep 17 00:00:00 2001 From: Michael Abbott Date: Sun, 17 Jan 2021 21:53:43 +0100 Subject: [PATCH 2/9] oops --- src/upsample.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/upsample.jl b/src/upsample.jl index 876c4b31c..bc6482458 100644 --- a/src/upsample.jl +++ b/src/upsample.jl @@ -14,7 +14,7 @@ See also [`upsample_bilinear`](@ref), for two dimensions of an `N=4` array. # Example ```jldoctest julia> upsample_nearest([1 2 3; 4 5 6], (2,3)) -4×9 Matrix{Int64}: +4×9 Array{$Int,2}: 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 @@ -60,6 +60,7 @@ function ChainRulesCore.rrule(::typeof(upsample_nearest), x::AbstractArray, s::T return Ω, upsample_nearest_pullback end +""" Upsamples the first 2 dimensions of the array `x` by the upsample factors stored in `k`, using bilinear interpolation. From 96ec8f96f7ce4fdec1a0194f14a2f892806312ba Mon Sep 17 00:00:00 2001 From: Michael Abbott Date: Sun, 17 Jan 2021 22:09:37 +0100 Subject: [PATCH 3/9] extend all the docstrings in this file, and fix some types & errors unrelated to the PR, but while I'm here... --- src/upsample.jl | 91 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 13 deletions(-) diff --git a/src/upsample.jl b/src/upsample.jl index bc6482458..3ade46483 100644 --- a/src/upsample.jl +++ b/src/upsample.jl @@ -61,20 +61,38 @@ function ChainRulesCore.rrule(::typeof(upsample_nearest), x::AbstractArray, s::T end """ + upsample_bilinear(x::AbstractArray{<:Number,4}, ks::NTuple{2,Int}) + upsample_bilinear(x::AbstractArray{<:Number,4}, k::Int) -Upsamples the first 2 dimensions of the array `x` by the upsample factors stored in `k`, -using bilinear interpolation. +Upsamples the first 2 dimensions of the array `x` by the upsample factors stored in `ks`, +using bilinear interpolation. One integer is equivalent to `ks = (k,k)`. -The size of the output is equal to -`(k[1]*S1, k[2]*S2, S3, S4)`, where `S1, S2, S3, S4 = size(x)`. +The size of the output is equal to +`(ks[1]*S1, ks[2]*S2, S3, S4)`, where `S1, S2, S3, S4 = size(x)`. The interpolation grid is identical to the one used by `imresize` from `Images.jl`. -Currently only 2d upsampling is supported. +Only two-dimensional upsampling is supported, hence "bi-linear". +See also [`upsample_nearest`](@ref) which allows any dimensions. + +# Example +```jldoctest +julia> upsample_bilinear(reshape([1 2 3; 4 5 6], 2,3,1,1), (2,4)) +4×12×1×1 Array{Float64, 4}: +[:, :, 1, 1] = + 1.0 1.0 1.125 1.375 1.625 1.875 2.125 2.375 2.625 2.875 3.0 3.0 + 1.75 1.75 1.875 2.125 2.375 2.625 2.875 3.125 3.375 3.625 3.75 3.75 + 3.25 3.25 3.375 3.625 3.875 4.125 4.375 4.625 4.875 5.125 5.25 5.25 + 4.0 4.0 4.125 4.375 4.625 4.875 5.125 5.375 5.625 5.875 6.0 6.0 +``` """ -function upsample_bilinear(x::AbstractArray{T,4}, k::NTuple{2,Int}) where T +upsample_bilinear(x::AbstractArray{<:Number,4}, k::Int) = upsample_bilinear(x, (k,k)) + +upsample_bilinear(x::AbstractArray{<:Integer,4}, k::NTuple{2,Int}) = upsample_bilinear(float(x), k) + +function upsample_bilinear(x::AbstractArray{<:Number,4}, k::NTuple{2,Int}) # This function is gpu friendly - + imgsize = size(x) newsize = get_newsize(imgsize, k) @@ -284,20 +302,67 @@ end """ pixel_shuffle(x, r) - + Pixel shuffling operation. `r` is the upscale factor for shuffling. The operation converts an input of size [W,H,r²C,N] to size [rW,rH,C,N] -Used extensively in super-resolution networks to upsample + +Used extensively in super-resolution networks to upsample towards high resolution features. +Reference : https://arxiv.org/abs/1609.05158 -Reference : https://arxiv.org/pdf/1609.05158.pdf +# Example +```jldoctest +julia> x = [10i + j + channel/10 for i in 1:2, j in 1:3, channel in 1:4, batch in 1:1] +2×3×4×1 Array{Float64, 4}: +[:, :, 1, 1] = + 11.1 12.1 13.1 + 21.1 22.1 23.1 + +[:, :, 2, 1] = + 11.2 12.2 13.2 + 21.2 22.2 23.2 + +[:, :, 3, 1] = + 11.3 12.3 13.3 + 21.3 22.3 23.3 + +[:, :, 4, 1] = + 11.4 12.4 13.4 + 21.4 22.4 23.4 + +julia> pixel_shuffle(x, 2) +4×6×1×1 Array{Float64, 4}: +[:, :, 1, 1] = + 11.1 11.3 12.1 12.3 13.1 13.3 + 11.2 11.4 12.2 12.4 13.2 13.4 + 21.1 21.3 22.1 22.3 23.1 23.3 + 21.2 21.4 22.2 22.4 23.2 23.4 + +julia> y = [i + channel/10 for i in 1:3, channel in 1:6, batch in 1:1] +3×6×1 Array{Float64, 3}: +[:, :, 1] = + 1.1 1.2 1.3 1.4 1.5 1.6 + 2.1 2.2 2.3 2.4 2.5 2.6 + 3.1 3.2 3.3 3.4 3.5 3.6 + +julia> pixel_shuffle(y, 2) +6×3×1 Array{Float64, 3}: +[:, :, 1] = + 1.1 1.3 1.5 + 1.2 1.4 1.6 + 2.1 2.3 2.5 + 2.2 2.4 2.6 + 3.1 3.3 3.5 + 3.2 3.4 3.6 + + ``` """ function pixel_shuffle(x::AbstractArray, r::Integer) - @assert ndims(x) > 2 + ndims(x) > 2 || throw(ArgumentError("expected x with at least 3 dimensions")) d = ndims(x) - 2 sizein = size(x)[1:d] - cin, n = size(x, d+1), size(x, d+2) - @assert cin % r^d == 0 + cin, n = size(x, d+1), size(x, d+2) + cin % r^d == 0 || throw(ArgumentError("expected channel dimension to be divisible by r^d = $(r^d), where d=$d is the number of spatial dimensions. Given r=$r, input size(x) = $(size(x))")) cout = cin ÷ r^d # x = reshape(x, sizein..., fill(r, d)..., cout, n) # bug https://github.com/FluxML/Zygote.jl/issues/866 x = reshape(x, sizein..., ntuple(i->r, d)..., cout, n) From fbda08766dd4bb75919f2696c28871467ea85621 Mon Sep 17 00:00:00 2001 From: Michael Abbott Date: Sun, 17 Jan 2021 22:22:56 +0100 Subject: [PATCH 4/9] one more error case --- src/upsample.jl | 5 ++++- test/upsample.jl | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/upsample.jl b/src/upsample.jl index 3ade46483..45dbc0755 100644 --- a/src/upsample.jl +++ b/src/upsample.jl @@ -21,7 +21,10 @@ julia> upsample_nearest([1 2 3; 4 5 6], (2,3)) 4 4 4 5 5 5 6 6 6 ``` """ -upsample_nearest(x::AbstractArray, s::Integer) = upsample_nearest(x, ntuple(_->s, ndims(x)-2)) +function upsample_nearest(x::AbstractArray, s::Integer) + ndims(x) > 2 || throw(ArgumentError("expected x with at least 3 dimensions")) + upsample_nearest(x, ntuple(_->s, ndims(x)-2)) +end function upsample_nearest(x::AbstractArray{T,N}, scales::NTuple{S, <:Integer}) where {T,N,S} S in 1:N || throw(ArgumentError("can't upsample ndims(x)=$N with scale=$scales")) diff --git a/test/upsample.jl b/test/upsample.jl index 8b5cb5ba7..26841d08b 100644 --- a/test/upsample.jl +++ b/test/upsample.jl @@ -8,6 +8,7 @@ @test_throws ArgumentError ∇upsample_nearest(y, (2,4)) @test_throws ArgumentError upsample_nearest(x, (1,2,3,4,5)) + @test_throws ArgumentError upsample_nearest(upsample_nearest(rand(2,3),4), 5) end @testset "upsample_bilinear 2d" begin From d52f1fc7d89ca34beb26971ae4ca84e92390de2f Mon Sep 17 00:00:00 2001 From: Michael Abbott Date: Mon, 18 Jan 2021 13:00:53 +0100 Subject: [PATCH 5/9] Revert "extend all the docstrings in this file, and fix some types & errors" This reverts commit 96ec8f96f7ce4fdec1a0194f14a2f892806312ba. --- src/upsample.jl | 91 +++++++------------------------------------------ 1 file changed, 13 insertions(+), 78 deletions(-) diff --git a/src/upsample.jl b/src/upsample.jl index 45dbc0755..a2f9f764e 100644 --- a/src/upsample.jl +++ b/src/upsample.jl @@ -64,38 +64,20 @@ function ChainRulesCore.rrule(::typeof(upsample_nearest), x::AbstractArray, s::T end """ - upsample_bilinear(x::AbstractArray{<:Number,4}, ks::NTuple{2,Int}) - upsample_bilinear(x::AbstractArray{<:Number,4}, k::Int) -Upsamples the first 2 dimensions of the array `x` by the upsample factors stored in `ks`, -using bilinear interpolation. One integer is equivalent to `ks = (k,k)`. +Upsamples the first 2 dimensions of the array `x` by the upsample factors stored in `k`, +using bilinear interpolation. -The size of the output is equal to -`(ks[1]*S1, ks[2]*S2, S3, S4)`, where `S1, S2, S3, S4 = size(x)`. +The size of the output is equal to +`(k[1]*S1, k[2]*S2, S3, S4)`, where `S1, S2, S3, S4 = size(x)`. The interpolation grid is identical to the one used by `imresize` from `Images.jl`. -Only two-dimensional upsampling is supported, hence "bi-linear". -See also [`upsample_nearest`](@ref) which allows any dimensions. - -# Example -```jldoctest -julia> upsample_bilinear(reshape([1 2 3; 4 5 6], 2,3,1,1), (2,4)) -4×12×1×1 Array{Float64, 4}: -[:, :, 1, 1] = - 1.0 1.0 1.125 1.375 1.625 1.875 2.125 2.375 2.625 2.875 3.0 3.0 - 1.75 1.75 1.875 2.125 2.375 2.625 2.875 3.125 3.375 3.625 3.75 3.75 - 3.25 3.25 3.375 3.625 3.875 4.125 4.375 4.625 4.875 5.125 5.25 5.25 - 4.0 4.0 4.125 4.375 4.625 4.875 5.125 5.375 5.625 5.875 6.0 6.0 -``` +Currently only 2d upsampling is supported. """ -upsample_bilinear(x::AbstractArray{<:Number,4}, k::Int) = upsample_bilinear(x, (k,k)) - -upsample_bilinear(x::AbstractArray{<:Integer,4}, k::NTuple{2,Int}) = upsample_bilinear(float(x), k) - -function upsample_bilinear(x::AbstractArray{<:Number,4}, k::NTuple{2,Int}) +function upsample_bilinear(x::AbstractArray{T,4}, k::NTuple{2,Int}) where T # This function is gpu friendly - + imgsize = size(x) newsize = get_newsize(imgsize, k) @@ -305,67 +287,20 @@ end """ pixel_shuffle(x, r) - + Pixel shuffling operation. `r` is the upscale factor for shuffling. The operation converts an input of size [W,H,r²C,N] to size [rW,rH,C,N] - -Used extensively in super-resolution networks to upsample +Used extensively in super-resolution networks to upsample towards high resolution features. -Reference : https://arxiv.org/abs/1609.05158 -# Example -```jldoctest -julia> x = [10i + j + channel/10 for i in 1:2, j in 1:3, channel in 1:4, batch in 1:1] -2×3×4×1 Array{Float64, 4}: -[:, :, 1, 1] = - 11.1 12.1 13.1 - 21.1 22.1 23.1 - -[:, :, 2, 1] = - 11.2 12.2 13.2 - 21.2 22.2 23.2 - -[:, :, 3, 1] = - 11.3 12.3 13.3 - 21.3 22.3 23.3 - -[:, :, 4, 1] = - 11.4 12.4 13.4 - 21.4 22.4 23.4 - -julia> pixel_shuffle(x, 2) -4×6×1×1 Array{Float64, 4}: -[:, :, 1, 1] = - 11.1 11.3 12.1 12.3 13.1 13.3 - 11.2 11.4 12.2 12.4 13.2 13.4 - 21.1 21.3 22.1 22.3 23.1 23.3 - 21.2 21.4 22.2 22.4 23.2 23.4 - -julia> y = [i + channel/10 for i in 1:3, channel in 1:6, batch in 1:1] -3×6×1 Array{Float64, 3}: -[:, :, 1] = - 1.1 1.2 1.3 1.4 1.5 1.6 - 2.1 2.2 2.3 2.4 2.5 2.6 - 3.1 3.2 3.3 3.4 3.5 3.6 - -julia> pixel_shuffle(y, 2) -6×3×1 Array{Float64, 3}: -[:, :, 1] = - 1.1 1.3 1.5 - 1.2 1.4 1.6 - 2.1 2.3 2.5 - 2.2 2.4 2.6 - 3.1 3.3 3.5 - 3.2 3.4 3.6 - - ``` +Reference : https://arxiv.org/pdf/1609.05158.pdf """ function pixel_shuffle(x::AbstractArray, r::Integer) - ndims(x) > 2 || throw(ArgumentError("expected x with at least 3 dimensions")) + @assert ndims(x) > 2 d = ndims(x) - 2 sizein = size(x)[1:d] - cin, n = size(x, d+1), size(x, d+2) - cin % r^d == 0 || throw(ArgumentError("expected channel dimension to be divisible by r^d = $(r^d), where d=$d is the number of spatial dimensions. Given r=$r, input size(x) = $(size(x))")) + cin, n = size(x, d+1), size(x, d+2) + @assert cin % r^d == 0 cout = cin ÷ r^d # x = reshape(x, sizein..., fill(r, d)..., cout, n) # bug https://github.com/FluxML/Zygote.jl/issues/866 x = reshape(x, sizein..., ntuple(i->r, d)..., cout, n) From 6b8769026ed67bb3e3b46ec84ea29e30711a4992 Mon Sep 17 00:00:00 2001 From: Michael Abbott Date: Mon, 18 Jan 2021 13:05:02 +0100 Subject: [PATCH 6/9] fix an accidental deletion --- src/upsample.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/upsample.jl b/src/upsample.jl index a2f9f764e..212870f31 100644 --- a/src/upsample.jl +++ b/src/upsample.jl @@ -64,6 +64,7 @@ function ChainRulesCore.rrule(::typeof(upsample_nearest), x::AbstractArray, s::T end """ + upsample_bilinear(x::AbstractArray{<:Number,4}, k::NTuple{2,Int}) Upsamples the first 2 dimensions of the array `x` by the upsample factors stored in `k`, using bilinear interpolation. From eecd3c4bc492ee05c6b6c63d6b8b623085698e7f Mon Sep 17 00:00:00 2001 From: Michael Abbott Date: Mon, 18 Jan 2021 13:07:38 +0100 Subject: [PATCH 7/9] remove one-integer scale, require a tuple --- src/upsample.jl | 19 ++++++++++--------- test/upsample.jl | 5 ++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/upsample.jl b/src/upsample.jl index 212870f31..38a6766de 100644 --- a/src/upsample.jl +++ b/src/upsample.jl @@ -3,11 +3,10 @@ export upsample_nearest, ∇upsample_nearest, pixel_shuffle """ - upsample_nearest(x::AbstractArray{T,N}, scale) + upsample_nearest(x::AbstractArray, scale::NTuple{S,Int}) -Upsamples by an integer multiple. For `scale::Integer`, this applies to the first -`N-2` dimensions of `x` (the remainder assumed to be channel & batch dimensions). -For `scale::Tuple`, the first `length(scale)` dimensions are altered. +Upsamples by integer multiples along the first `S` dimensions. +Subsequent dimensions of `x` are not altered. See also [`upsample_bilinear`](@ref), for two dimensions of an `N=4` array. @@ -19,13 +18,15 @@ julia> upsample_nearest([1 2 3; 4 5 6], (2,3)) 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 4 4 4 5 5 5 6 6 6 + +julia> upsample_nearest([1 2 3; 4 5 6], (2,)) +4×3 Array{$Int,1}: + 1 2 3 + 1 2 3 + 4 5 6 + 4 5 6 ``` """ -function upsample_nearest(x::AbstractArray, s::Integer) - ndims(x) > 2 || throw(ArgumentError("expected x with at least 3 dimensions")) - upsample_nearest(x, ntuple(_->s, ndims(x)-2)) -end - function upsample_nearest(x::AbstractArray{T,N}, scales::NTuple{S, <:Integer}) where {T,N,S} S in 1:N || throw(ArgumentError("can't upsample ndims(x)=$N with scale=$scales")) outsize = ntuple(d -> d<=S ? scales[d] * size(x,d) : size(x,d), N) diff --git a/test/upsample.jl b/test/upsample.jl index 26841d08b..9e063053a 100644 --- a/test/upsample.jl +++ b/test/upsample.jl @@ -1,6 +1,6 @@ -@testset "upsample_nearest" begin +@testset "upsample_nearest, integer scale via reshape" begin x = reshape(Float32[1. 2.; 3. 4.], (2,2,1,1)) - @test upsample_nearest(x, 3)[1,:] == [1,1,1, 2,2,2] + @test upsample_nearest(x, (3,3))[1,:] == [1,1,1, 2,2,2] y = upsample_nearest(x, (2,3)) @test size(y) == (4,6,1,1) @@ -8,7 +8,6 @@ @test_throws ArgumentError ∇upsample_nearest(y, (2,4)) @test_throws ArgumentError upsample_nearest(x, (1,2,3,4,5)) - @test_throws ArgumentError upsample_nearest(upsample_nearest(rand(2,3),4), 5) end @testset "upsample_bilinear 2d" begin From 5ab154a60949459fb0b7c0e07dfc110dd81f4327 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 19 Jan 2021 08:52:39 +0100 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: Carlo Lucibello --- src/upsample.jl | 2 +- test/upsample.jl | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/upsample.jl b/src/upsample.jl index 38a6766de..5126441a2 100644 --- a/src/upsample.jl +++ b/src/upsample.jl @@ -60,7 +60,7 @@ end function ChainRulesCore.rrule(::typeof(upsample_nearest), x::AbstractArray, s::Tuple) Ω = upsample_nearest(x, s) - upsample_nearest_pullback(Δ) = (NO_FIELDS, ∇upsample_nearest(Δ, k), DoesNotExist()) + upsample_nearest_pullback(Δ) = (NO_FIELDS, ∇upsample_nearest(Δ, s), DoesNotExist()) return Ω, upsample_nearest_pullback end diff --git a/test/upsample.jl b/test/upsample.jl index 9e063053a..0f0c3f54d 100644 --- a/test/upsample.jl +++ b/test/upsample.jl @@ -5,7 +5,7 @@ y = upsample_nearest(x, (2,3)) @test size(y) == (4,6,1,1) ∇upsample_nearest(y, (2,3)) == [6 12; 18 24] - +gradtest(x -> upsample_nearest(x, (2,3)), rand(2,2,1,1), check_rrule=true) @test_throws ArgumentError ∇upsample_nearest(y, (2,4)) @test_throws ArgumentError upsample_nearest(x, (1,2,3,4,5)) end @@ -102,4 +102,3 @@ end gradtest(x -> pixel_shuffle(x, r), x) end end - From b8f40f844f4e3a5b588284f50dbca42ba2598c29 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 19 Jan 2021 09:36:23 +0100 Subject: [PATCH 9/9] Update test/upsample.jl --- test/upsample.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/upsample.jl b/test/upsample.jl index 0f0c3f54d..08886b4d0 100644 --- a/test/upsample.jl +++ b/test/upsample.jl @@ -5,7 +5,9 @@ y = upsample_nearest(x, (2,3)) @test size(y) == (4,6,1,1) ∇upsample_nearest(y, (2,3)) == [6 12; 18 24] -gradtest(x -> upsample_nearest(x, (2,3)), rand(2,2,1,1), check_rrule=true) + + gradtest(x -> upsample_nearest(x, (2,3)), rand(2,2,1,1), check_rrule=false) + @test_throws ArgumentError ∇upsample_nearest(y, (2,4)) @test_throws ArgumentError upsample_nearest(x, (1,2,3,4,5)) end