Skip to content

Commit

Permalink
Fixed indenting, deleted asserts, made one-liners.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregstrq committed Mar 31, 2022
1 parent c562ae1 commit bdcf670
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
16 changes: 4 additions & 12 deletions src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,11 @@ plan_irfft
##############################################################################

"""
fftshift!(dest, src, [dim])
fftshift!(dest, src, [dim])
Nonallocating version of [`fftshift`](@ref). Stores the result of the shift of the `src` array into the `dest` array.
"""
function fftshift!(dest, src, dim = 1:ndims(src))
@assert size(dest)==size(src)
s = ntuple(d -> d in dim ? div(size(dest,d),2) : 0, Val(ndims(dest)))
circshift!(dest, src, s)
end
Expand All @@ -372,18 +371,14 @@ The output of `fftshift` is allocated. If one desires to store the output in a p
"""
fftshift

function fftshift(x, dim = 1:ndims(x))
dest = similar(x)
fftshift!(dest, x, dim)
end
fftshift(x, dim = 1:ndims(x)) = fftshift!(similar(x), x, dim)

"""
ifftshift!(dest, src, [dim])
ifftshift!(dest, src, [dim])
Nonallocating version of [`ifftshift`](@ref). Stores the result of the shift of the `src` array into the `dest` array.
"""
function ifftshift!(dest, src, dim = 1:ndims(src))
@assert size(dest)==size(src)
s = ntuple(d -> d in dim ? -div(size(src,d),2) : 0, Val(ndims(src)))
circshift!(dest, src, s)
end
Expand All @@ -405,10 +400,7 @@ The output of `ifftshift` is allocated. If one desires to store the output in a
"""
ifftshift

function ifftshift(x, dim = 1:ndims(x))
dest = similar(x)
ifftshift!(dest, x, dim)
end
ifftshift(x, dim = 1:ndims(x)) = ifftshift!(similar(x), x, dim)

##############################################################################

Expand Down
28 changes: 14 additions & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,37 +103,37 @@ end
@test @inferred(AbstractFFTs.fftshift([1 2 3])) == [3 1 2]
@test @inferred(AbstractFFTs.fftshift([1, 2, 3])) == [3, 1, 2]
@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6])) == [6 4 5; 3 1 2]
a = [0 0 0]
b = [0, 0, 0]
c = [0 0 0; 0 0 0]
@test (AbstractFFTs.fftshift!(a, [1 2 3]); a == [3 1 2])
@test (AbstractFFTs.fftshift!(b, [1, 2, 3]); b == [3, 1, 2])
a = [0 0 0]
b = [0, 0, 0]
c = [0 0 0; 0 0 0]
@test (AbstractFFTs.fftshift!(a, [1 2 3]); a == [3 1 2])
@test (AbstractFFTs.fftshift!(b, [1, 2, 3]); b == [3, 1, 2])
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6]); c == [6 4 5; 3 1 2])

@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6], 1)) == [4 5 6; 1 2 3]
@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6], ())) == [1 2 3; 4 5 6]
@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6], (1,2))) == [6 4 5; 3 1 2]
@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6], 1:2)) == [6 4 5; 3 1 2]
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], 1); c == [4 5 6; 1 2 3])
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], ()); c == [1 2 3; 4 5 6])
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], (1,2)); c == [6 4 5; 3 1 2])
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], 1:2); c == [6 4 5; 3 1 2])
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], 1); c == [4 5 6; 1 2 3])
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], ()); c == [1 2 3; 4 5 6])
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], (1,2)); c == [6 4 5; 3 1 2])
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], 1:2); c == [6 4 5; 3 1 2])

@test @inferred(AbstractFFTs.ifftshift([1 2 3])) == [2 3 1]
@test @inferred(AbstractFFTs.ifftshift([1, 2, 3])) == [2, 3, 1]
@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6])) == [5 6 4; 2 3 1]
@test (AbstractFFTs.ifftshift!(a, [1 2 3]); a == [2 3 1])
@test (AbstractFFTs.ifftshift!(a, [1 2 3]); a == [2 3 1])
@test (AbstractFFTs.ifftshift!(b, [1, 2, 3]); b == [2, 3, 1])
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6]); c == [5 6 4; 2 3 1])

@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6], 1)) == [4 5 6; 1 2 3]
@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6], ())) == [1 2 3; 4 5 6]
@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6], (1,2))) == [5 6 4; 2 3 1]
@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6], 1:2)) == [5 6 4; 2 3 1]
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], 1); c == [4 5 6; 1 2 3])
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], ()); c == [1 2 3; 4 5 6])
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], (1,2)); c == [5 6 4; 2 3 1])
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], 1:2); c == [5 6 4; 2 3 1])
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], 1); c == [4 5 6; 1 2 3])
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], ()); c == [1 2 3; 4 5 6])
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], (1,2)); c == [5 6 4; 2 3 1])
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], 1:2); c == [5 6 4; 2 3 1])
end

@testset "FFT Frequencies" begin
Expand Down

0 comments on commit bdcf670

Please sign in to comment.