Skip to content

Commit bdcf670

Browse files
committed
Fixed indenting, deleted asserts, made one-liners.
1 parent c562ae1 commit bdcf670

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

src/definitions.jl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,11 @@ plan_irfft
345345
##############################################################################
346346

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

375-
function fftshift(x, dim = 1:ndims(x))
376-
dest = similar(x)
377-
fftshift!(dest, x, dim)
378-
end
374+
fftshift(x, dim = 1:ndims(x)) = fftshift!(similar(x), x, dim)
379375

380376
"""
381-
ifftshift!(dest, src, [dim])
377+
ifftshift!(dest, src, [dim])
382378
383379
Nonallocating version of [`ifftshift`](@ref). Stores the result of the shift of the `src` array into the `dest` array.
384380
"""
385381
function ifftshift!(dest, src, dim = 1:ndims(src))
386-
@assert size(dest)==size(src)
387382
s = ntuple(d -> d in dim ? -div(size(src,d),2) : 0, Val(ndims(src)))
388383
circshift!(dest, src, s)
389384
end
@@ -405,10 +400,7 @@ The output of `ifftshift` is allocated. If one desires to store the output in a
405400
"""
406401
ifftshift
407402

408-
function ifftshift(x, dim = 1:ndims(x))
409-
dest = similar(x)
410-
ifftshift!(dest, x, dim)
411-
end
403+
ifftshift(x, dim = 1:ndims(x)) = ifftshift!(similar(x), x, dim)
412404

413405
##############################################################################
414406

test/runtests.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,37 @@ end
103103
@test @inferred(AbstractFFTs.fftshift([1 2 3])) == [3 1 2]
104104
@test @inferred(AbstractFFTs.fftshift([1, 2, 3])) == [3, 1, 2]
105105
@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6])) == [6 4 5; 3 1 2]
106-
a = [0 0 0]
107-
b = [0, 0, 0]
108-
c = [0 0 0; 0 0 0]
109-
@test (AbstractFFTs.fftshift!(a, [1 2 3]); a == [3 1 2])
110-
@test (AbstractFFTs.fftshift!(b, [1, 2, 3]); b == [3, 1, 2])
106+
a = [0 0 0]
107+
b = [0, 0, 0]
108+
c = [0 0 0; 0 0 0]
109+
@test (AbstractFFTs.fftshift!(a, [1 2 3]); a == [3 1 2])
110+
@test (AbstractFFTs.fftshift!(b, [1, 2, 3]); b == [3, 1, 2])
111111
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6]); c == [6 4 5; 3 1 2])
112112

113113
@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6], 1)) == [4 5 6; 1 2 3]
114114
@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6], ())) == [1 2 3; 4 5 6]
115115
@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6], (1,2))) == [6 4 5; 3 1 2]
116116
@test @inferred(AbstractFFTs.fftshift([1 2 3; 4 5 6], 1:2)) == [6 4 5; 3 1 2]
117-
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], 1); c == [4 5 6; 1 2 3])
118-
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], ()); c == [1 2 3; 4 5 6])
119-
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], (1,2)); c == [6 4 5; 3 1 2])
120-
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], 1:2); c == [6 4 5; 3 1 2])
117+
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], 1); c == [4 5 6; 1 2 3])
118+
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], ()); c == [1 2 3; 4 5 6])
119+
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], (1,2)); c == [6 4 5; 3 1 2])
120+
@test (AbstractFFTs.fftshift!(c, [1 2 3; 4 5 6], 1:2); c == [6 4 5; 3 1 2])
121121

122122
@test @inferred(AbstractFFTs.ifftshift([1 2 3])) == [2 3 1]
123123
@test @inferred(AbstractFFTs.ifftshift([1, 2, 3])) == [2, 3, 1]
124124
@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6])) == [5 6 4; 2 3 1]
125-
@test (AbstractFFTs.ifftshift!(a, [1 2 3]); a == [2 3 1])
125+
@test (AbstractFFTs.ifftshift!(a, [1 2 3]); a == [2 3 1])
126126
@test (AbstractFFTs.ifftshift!(b, [1, 2, 3]); b == [2, 3, 1])
127127
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6]); c == [5 6 4; 2 3 1])
128128

129129
@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6], 1)) == [4 5 6; 1 2 3]
130130
@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6], ())) == [1 2 3; 4 5 6]
131131
@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6], (1,2))) == [5 6 4; 2 3 1]
132132
@test @inferred(AbstractFFTs.ifftshift([1 2 3; 4 5 6], 1:2)) == [5 6 4; 2 3 1]
133-
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], 1); c == [4 5 6; 1 2 3])
134-
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], ()); c == [1 2 3; 4 5 6])
135-
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], (1,2)); c == [5 6 4; 2 3 1])
136-
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], 1:2); c == [5 6 4; 2 3 1])
133+
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], 1); c == [4 5 6; 1 2 3])
134+
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], ()); c == [1 2 3; 4 5 6])
135+
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], (1,2)); c == [5 6 4; 2 3 1])
136+
@test (AbstractFFTs.ifftshift!(c, [1 2 3; 4 5 6], 1:2); c == [5 6 4; 2 3 1])
137137
end
138138

139139
@testset "FFT Frequencies" begin

0 commit comments

Comments
 (0)