Skip to content

Commit

Permalink
Merge pull request #17 from ToucheSir/bc/test_softmax_dims
Browse files Browse the repository at this point in the history
Test `softmax` with varying dimensions
  • Loading branch information
CarloLucibello authored Jun 27, 2021
2 parents acd314f + 2c1f05c commit ba9a1c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions test/softmax.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@testset "softmax" begin
for dims in [(5,5), (5,)]
x = randn(Float64, dims)
y = softmax(x)
dy = randn(Float64, dims)
gputest(softmax, x)
gputest(∇softmax, dy, x, y, checkgrad=false)
y = logsoftmax(x)
gputest(logsoftmax, x)
gputest(∇logsoftmax, dy, x, y, checkgrad=false)
for (sz, dims) in [((5,), :), ((5,), 1), ((5,5), :), ((5,5), 1), ((5,5), 2), ((5,5,5,5), (2,3)), ((5,5,5,5), (2,4))]
x = randn(Float64, sz)
y = softmax(x, dims=dims)
dy = randn(Float64, sz)
gputest(softmax, x, dims=dims)
gputest(∇softmax, dy, x, y, dims=dims, checkgrad=false)
y = logsoftmax(x, dims=dims)
gputest(logsoftmax, x, dims=dims)
gputest(∇logsoftmax, dy, x, y, dims=dims, checkgrad=false)
end
end
6 changes: 3 additions & 3 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function gputest(f, xs...; checkgrad=true, atol=1e-10)
function gputest(f, xs...; checkgrad=true, atol=1e-10, kws...)
cpu_in = xs
gpu_in = CuArray.(xs)

cpu_out = f(cpu_in...)
gpu_out = f(gpu_in...)
cpu_out = f(cpu_in...; kws...)
gpu_out = f(gpu_in...; kws...)
@test collect(cpu_out) collect(gpu_out)

if checkgrad
Expand Down

0 comments on commit ba9a1c0

Please sign in to comment.