Skip to content

Commit

Permalink
make fftshift and ifftshift take iterables as dimension arguments (#2…
Browse files Browse the repository at this point in the history
…0461)

make fftshift and ifftshift take iterables as dimension arguments
  • Loading branch information
JKrehl authored and stevengj committed Feb 7, 2017
1 parent 8d657c4 commit 7e27a28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions base/dft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,16 @@ fftshift(x)

function fftshift(x,dim)
s = zeros(Int,ndims(x))
s[dim] = div(size(x,dim),2)
for i in dim
s[i] = div(size(x,i),2)
end
circshift(x, s)
end

"""
fftshift(x,dim)
Swap the first and second halves of the given dimension of array `x`.
Swap the first and second halves of the given dimension or iterable of dimensions of array `x`.
"""
fftshift(x,dim)

Expand All @@ -387,7 +389,9 @@ ifftshift

function ifftshift(x,dim)
s = zeros(Int,ndims(x))
s[dim] = -div(size(x,dim),2)
for i in dim
s[i] = -div(size(x,i),2)
end
circshift(x, s)
end

Expand Down
12 changes: 12 additions & 0 deletions test/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,25 @@ si = [0.9967207836936347,-1.4940914728163142,1.2841226760316475,-0.4524417279474
@test_throws ArgumentError filt!([1, 2], [1], [1], [1])
@test xcorr([1, 2], [3, 4]) == [4, 11, 6]

# Shift-Functions
@test fftshift([1 2 3]) == [3 1 2]
@test fftshift([1, 2, 3]) == [3, 1, 2]
@test fftshift([1 2 3; 4 5 6]) == [6 4 5; 3 1 2]

@test fftshift([1 2 3; 4 5 6], 1) == [4 5 6; 1 2 3]
@test fftshift([1 2 3; 4 5 6], ()) == [1 2 3; 4 5 6]
@test fftshift([1 2 3; 4 5 6], (1,2)) == [6 4 5; 3 1 2]
@test fftshift([1 2 3; 4 5 6], 1:2) == [6 4 5; 3 1 2]

@test ifftshift([1 2 3]) == [2 3 1]
@test ifftshift([1, 2, 3]) == [2, 3, 1]
@test ifftshift([1 2 3; 4 5 6]) == [5 6 4; 2 3 1]

@test ifftshift([1 2 3; 4 5 6], 1) == [4 5 6; 1 2 3]
@test ifftshift([1 2 3; 4 5 6], ()) == [1 2 3; 4 5 6]
@test ifftshift([1 2 3; 4 5 6], (1,2)) == [5 6 4; 2 3 1]
@test ifftshift([1 2 3; 4 5 6], 1:2) == [5 6 4; 2 3 1]

# Convolution
a = [1., 2., 1., 2.]
b = [1., 2., 3.]
Expand Down

5 comments on commit 7e27a28

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something went wrong when running your job:

NanosoldierError: failed to run benchmarks against primary commit: ErrorException("failed process: Process(`sudo cset shield -e su nanosoldier -- -c ./benchscript.sh`, ProcessExited(1)) [1]")

Logs and partial data can be found here
cc @jrevels

@tkelman
Copy link
Contributor

@tkelman tkelman commented on 7e27a28 Feb 7, 2017

Choose a reason for hiding this comment

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

These should be fixed, can the fixes be deployed?

@jrevels
Copy link
Member

@jrevels jrevels commented on 7e27a28 Feb 7, 2017

Choose a reason for hiding this comment

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

I'm waiting until JuliaCI/Nanosoldier.jl#28 is ready (fixing serialization compatibility between BenchmarkTools versions) so that I can do the test runs all at once. That PR is waiting on JuliaCI/BaseBenchmarks.jl#62, which will hopefully pass CI soon.

@tkelman
Copy link
Contributor

@tkelman tkelman commented on 7e27a28 Feb 7, 2017

Choose a reason for hiding this comment

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

great, thanks for the update

Please sign in to comment.