Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pxl-th committed Dec 22, 2024
1 parent 8d2e009 commit 8514fa5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/testsuite/spectral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,19 @@ function spectral_testsuite(Backend)
spec = spectrogram(x;
n_fft=1024, hop_length=128, window,
center=true, normalized=false)

@test abs.(y).^2 spec

# Gradient with `0`s in spectrogram.
# We add small ϵ to spectrogram before computing power
# to prevent `NaN` in gradient due to `abs(0)`.
x = device(ones(Float32, 1024))
g = Zygote.gradient(x) do x
sum(spectrogram(x;
n_fft=1024, hop_length=128, window,
center=true, normalized=false))
end
@test !any(isnan.(g[1]))

# Batched.
x = device(rand(Float32, 1024, 3))
spec = spectrogram(x;
Expand Down

0 comments on commit 8514fa5

Please sign in to comment.