Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support complex input for upsample #421

Merged
merged 1 commit into from
Jun 14, 2022
Merged

Conversation

mloubout
Copy link
Contributor

The current implementation uses the array input type to convert width/height/.... which creates non-real numbers when the input is complex. This fixes it by using the real type.

src/upsample.jl Outdated
width_scale = T((in_w - 1) // (out_w - 1))
height_scale = T((in_h - 1) // (out_h - 1))
#real(T)() and // so that we can handle rationals (super slow)
width_scale =real(T)((in_w - 1) // (out_w - 1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind extracting out real(T) as RT or some like name? Otherwise this LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

test/upsample.jl Outdated
Comment on lines 177 to 193
for (d, method) in zip([1, 2, 3], [upsample_linear, upsample_bilinear, upsample_trilinear])
for (k, interp) in zip((2, tuple([2 for i=1:d]...)), [method, upsample_nearest])
x = randn(Complex{Float32}, (4,8,12)[1:d]..., 1, 1)
xup = interp(x, k)
@test size(xup)[1:d] == (8,16,24)[1:d]
@test real(xup) == interp(real(x), k)
@test imag(xup) == interp(imag(x), k)

xup = interp(x; size=(8,24,48)[1:d])
@test size(xup)[1:d] == (8,24,48)[1:d]
@test real(xup) == interp(real(x), size=(8,24,48)[1:d])
@test imag(xup) == interp(imag(x), size=(8,24,48)[1:d])
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (d, method) in zip([1, 2, 3], [upsample_linear, upsample_bilinear, upsample_trilinear])
for (k, interp) in zip((2, tuple([2 for i=1:d]...)), [method, upsample_nearest])
x = randn(Complex{Float32}, (4,8,12)[1:d]..., 1, 1)
xup = interp(x, k)
@test size(xup)[1:d] == (8,16,24)[1:d]
@test real(xup) == interp(real(x), k)
@test imag(xup) == interp(imag(x), k)
xup = interp(x; size=(8,24,48)[1:d])
@test size(xup)[1:d] == (8,24,48)[1:d]
@test real(xup) == interp(real(x), size=(8,24,48)[1:d])
@test imag(xup) == interp(imag(x), size=(8,24,48)[1:d])
end
end
for (d, method) in zip(1:3, [upsample_linear, upsample_bilinear, upsample_trilinear])
for (k, interp) in zip((2, ntuple(_ -> 2, d)), [method, upsample_nearest])
x = randn(ComplexF32, (4, 8, 12)[1:d]..., 1, 1)
upsize = (8, 16, 24)[1:d]
xup = interp(x, k)
@test size(xup)[1:d] == upsize
@test real(xup) == interp(real(x), k)
@test imag(xup) == interp(imag(x), k)
upsize = (8, 24, 48)[1:d]
xup = interp(x; size=upsize)
@test size(xup)[1:d] == upsize
@test real(xup) == interp(real(x), size=upsize)
@test imag(xup) == interp(imag(x), size=upsize)
end
end

One more touch-up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@ToucheSir ToucheSir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ToucheSir ToucheSir merged commit 4ebb419 into FluxML:master Jun 14, 2022
mloubout pushed a commit to mloubout/NNlib.jl that referenced this pull request Jun 14, 2022
support complex input for upsample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants