From 119f4f10ee6a671b74fc7f24a45fec97495c4c4a Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 31 Mar 2021 14:54:45 -0400 Subject: [PATCH 1/2] remove eltype conversion from create_bias --- src/utils.jl | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index b75d1e5a23..523f23a810 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -388,14 +388,10 @@ to the constructor's keyword `bias=bias`. function create_bias(weights::AbstractArray, bias::Bool, dims::Integer...) bias ? fill!(similar(weights, dims...), 0) : Zeros() end + function create_bias(weights::AbstractArray, bias::AbstractArray, dims::Integer...) size(bias) == dims || throw(DimensionMismatch("expected bias of size $(dims), got size $(size(bias))")) - if eltype(bias) == eltype(weights) - return bias - else - @warn "converting bias to match element type of weights" typeof(weights) typeof(bias) maxlog=3 _id=hash(dims) - return broadcast(eltype(weights), bias) - end + bias end """ From e5a9864bf5a7c7079d58beb58e12ac24a307cd2d Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 31 Mar 2021 14:55:17 -0400 Subject: [PATCH 2/2] skip tests of eltype conversion --- test/layers/basic.jl | 6 +++--- test/layers/conv.jl | 2 +- test/utils.jl | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/layers/basic.jl b/test/layers/basic.jl index cb321cccfb..30d830f8b4 100644 --- a/test/layers/basic.jl +++ b/test/layers/basic.jl @@ -38,10 +38,10 @@ import Flux: activations @test Dense(rand(100,10), false, tanh).σ == tanh @test Dense(rand(100,10), rand(100)).σ == identity @test Dense(rand(Float16, 100,10), true).bias isa Vector{Float16} # creates matching type - @test Dense(rand(Float16, 100,10), rand(100)).bias isa Vector{Float16} # converts to match + @test_skip Dense(rand(Float16, 100,10), rand(100)).bias isa Vector{Float16} # converts to match @test Dense(3,4; init=Base.randn, bias=true).bias isa Vector{Float64} - @test Dense(3,4; init=Base.randn, bias=[1,2,3,4]).bias isa Vector{Float64} + @test_skip Dense(3,4; init=Base.randn, bias=[1,2,3,4]).bias isa Vector{Float64} @test_throws MethodError Dense(10, 10.5) @test_throws MethodError Dense(10, 10.5, tanh) @@ -167,7 +167,7 @@ import Flux: activations @test size(b3(rand(4), rand(5))) == (3,) b4 = Flux.Bilinear(3,3,7; bias=1:7, init=Flux.zeros) - @test b4.bias isa Vector{Float32} + @test_skip b4.bias isa Vector{Float32} @test_throws ArgumentError Flux.Bilinear(rand(3)) # expects a 3-array @test_throws ArgumentError Flux.Bilinear(rand(3,4), false, tanh) diff --git a/test/layers/conv.jl b/test/layers/conv.jl index d8840031ae..f9af78dc08 100644 --- a/test/layers/conv.jl +++ b/test/layers/conv.jl @@ -194,7 +194,7 @@ end @test fun(rand(2,3,4,5), false).bias isa Flux.Zeros if fun == Conv @test fun(rand(2,3,4,5,6), rand(6)).bias isa Vector{Float64} - @test fun(rand(2,3,4,5,6), 1:6).bias isa Vector{Float64} + @test_skip fun(rand(2,3,4,5,6), 1:6).bias isa Vector{Float64} elseif fun == DepthwiseConv @test fun(rand(2,3,4,5,6), rand(30)).bias isa Vector{Float64} end diff --git a/test/utils.jl b/test/utils.jl index a8f402377a..682e8ed721 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -342,7 +342,7 @@ end testdense(m, bt) = @testset "Check layer $i" for (i, (l1, l2)) in enumerate(zip(m, dm(bt))) @test l1.W == l2.W @test l1.b == l2.b - @test typeof(l1.b) === typeof(l2.b) + @test_skip typeof(l1.b) === typeof(l2.b) end @testset "loadparams!" begin