Skip to content

Commit 8514fa5

Browse files
committed
Add test
1 parent 8d2e009 commit 8514fa5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/testsuite/spectral.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,19 @@ function spectral_testsuite(Backend)
110110
spec = spectrogram(x;
111111
n_fft=1024, hop_length=128, window,
112112
center=true, normalized=false)
113-
114113
@test abs.(y).^2 spec
115114

115+
# Gradient with `0`s in spectrogram.
116+
# We add small ϵ to spectrogram before computing power
117+
# to prevent `NaN` in gradient due to `abs(0)`.
118+
x = device(ones(Float32, 1024))
119+
g = Zygote.gradient(x) do x
120+
sum(spectrogram(x;
121+
n_fft=1024, hop_length=128, window,
122+
center=true, normalized=false))
123+
end
124+
@test !any(isnan.(g[1]))
125+
116126
# Batched.
117127
x = device(rand(Float32, 1024, 3))
118128
spec = spectrogram(x;

0 commit comments

Comments
 (0)