Skip to content

Commit 2782544

Browse files
committed
Merge remote-tracking branch 'origin/master' into backend-tests
2 parents 6d923c0 + 79789f2 commit 2782544

File tree

8 files changed

+102
-20
lines changed

8 files changed

+102
-20
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
version:
1616
- '1.0'
1717
- '1'
18-
# - 'nightly'
18+
- 'nightly'
1919
os:
2020
- ubuntu-latest
2121
- macOS-latest

.github/workflows/Invalidations.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Invalidations
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
# Skip intermediate builds: always.
8+
# Cancel intermediate builds: always.
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
evaluate:
14+
# Only run on PRs to the default branch.
15+
# In the PR trigger above branches can be specified only explicitly whereas this check should work for master, main, or any other default branch
16+
if: github.base_ref == github.event.repository.default_branch
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: julia-actions/setup-julia@v1
20+
with:
21+
version: '1'
22+
- uses: actions/checkout@v3
23+
- uses: julia-actions/julia-buildpkg@v1
24+
- uses: julia-actions/julia-invalidations@v1
25+
id: invs_pr
26+
27+
- uses: actions/checkout@v3
28+
with:
29+
ref: ${{ github.event.repository.default_branch }}
30+
- uses: julia-actions/julia-buildpkg@v1
31+
- uses: julia-actions/julia-invalidations@v1
32+
id: invs_default
33+
34+
- name: Report invalidation counts
35+
run: |
36+
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
37+
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
38+
- name: Check whether the number of invalidations increased
39+
if: steps.invs_pr.outputs.total > steps.invs_default.outputs.total
40+
run: exit 1

Project.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
name = "AbstractFFTs"
22
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
3-
version = "1.2.1"
3+
version = "1.3.1"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
88
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
99

10+
[weakdeps]
11+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
12+
13+
[extensions]
14+
AbstractFFTsChainRulesCoreExt = "ChainRulesCore"
15+
1016
[compat]
1117
ChainRulesCore = "1"
1218
julia = "^1.0"
1319

1420
[extras]
21+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
1522
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
1623
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1724
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1825
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1926

2027
[targets]
21-
test = ["ChainRulesTestUtils", "Random", "Test", "Unitful"]
28+
test = ["ChainRulesCore", "ChainRulesTestUtils", "Random", "Test", "Unitful"]

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
A general framework for fast Fourier transforms (FFTs) in Julia.
44

5-
[![Travis](https://travis-ci.org/JuliaMath/AbstractFFTs.jl.svg?branch=master)](https://travis-ci.org/JuliaMath/AbstractFFTs.jl)
6-
[![Coveralls](https://coveralls.io/repos/github/JuliaMath/AbstractFFTs.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaMath/AbstractFFTs.jl?branch=master)
5+
[![GHA](https://github.com/JuliaMath/AbstractFFTs.jl/workflows/CI/badge.svg)](https://github.com/JuliaMath/AbstractFFTs.jl/actions?query=workflow%3ACI+branch%3Amaster)
6+
[![Codecov](http://codecov.io/github/JuliaMath/AbstractFFTs.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaMath/AbstractFFTs.jl?branch=master)
77

88
Documentation:
99
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaMath.github.io/AbstractFFTs.jl/stable)
10-
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://JuliaMath.github.io/AbstractFFTs.jl/latest)
10+
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://JuliaMath.github.io/AbstractFFTs.jl/dev)
1111

1212
This package is mainly not intended to be used directly.
1313
Instead, developers of packages that implement FFTs (such as [FFTW.jl](https://github.com/JuliaMath/FFTW.jl) or [FastTransforms.jl](https://github.com/JuliaApproximation/FastTransforms.jl))
@@ -36,5 +36,6 @@ To define a new FFT implementation in your own module, you should
3636

3737
* You can also define similar methods of `plan_rfft` and `plan_brfft` for real-input FFTs.
3838

39-
The normalization convention for your FFT should be that it computes yₖ = ∑ⱼ xⱼ exp(-2πi jk/n) for a transform of
40-
length n, and the "backwards" (unnormalized inverse) transform computes the same thing but with exp(+2πi jk/n).
39+
The normalization convention for your FFT should be that it computes $y_k = \sum_j \exp\(-2 \pi i \cdot \frac{j k}{n}\)$
40+
for a transform of length $n$, and the "backwards" (unnormalized inverse) transform computes the same thing but with
41+
$\exp\(+2 \pi i \cdot \frac{j k}{n}\)$.

src/chainrules.jl renamed to ext/AbstractFFTsChainRulesCoreExt.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# ffts
1+
module AbstractFFTsChainRulesCoreExt
2+
3+
using AbstractFFTs
4+
import ChainRulesCore
5+
26
function ChainRulesCore.frule((_, Δx, _), ::typeof(fft), x::AbstractArray, dims)
37
y = fft(x, dims)
48
Δy = fft(Δx, dims)
@@ -46,7 +50,7 @@ function ChainRulesCore.frule((_, Δx, _), ::typeof(ifft), x::AbstractArray, dim
4650
end
4751
function ChainRulesCore.rrule(::typeof(ifft), x::AbstractArray, dims)
4852
y = ifft(x, dims)
49-
invN = normalization(y, dims)
53+
invN = AbstractFFTs.normalization(y, dims)
5054
project_x = ChainRulesCore.ProjectTo(x)
5155
function ifft_pullback(ȳ)
5256
= project_x(invN .* fft(ChainRulesCore.unthunk(ȳ), dims))
@@ -66,7 +70,7 @@ function ChainRulesCore.rrule(::typeof(irfft), x::AbstractArray, d::Int, dims)
6670
# compute scaling factors
6771
halfdim = first(dims)
6872
n = size(x, halfdim)
69-
invN = normalization(y, dims)
73+
invN = AbstractFFTs.normalization(y, dims)
7074
twoinvN = 2 * invN
7175
scale = reshape(
7276
[i == 1 || (i == n && 2 * (i - 1) == d) ? invN : twoinvN for i in 1:n],
@@ -150,3 +154,5 @@ function ChainRulesCore.rrule(::typeof(ifftshift), x::AbstractArray, dims)
150154
end
151155
return y, ifftshift_pullback
152156
end
157+
158+
end # module

src/AbstractFFTs.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
module AbstractFFTs
22

3-
import ChainRulesCore
4-
53
export fft, ifft, bfft, fft!, ifft!, bfft!,
64
plan_fft, plan_ifft, plan_bfft, plan_fft!, plan_ifft!, plan_bfft!,
75
rfft, irfft, brfft, plan_rfft, plan_irfft, plan_brfft,
86
fftdims, fftshift, ifftshift, fftshift!, ifftshift!, Frequencies, fftfreq, rfftfreq
97

108
include("definitions.jl")
11-
include("chainrules.jl")
129
include("TestUtils.jl")
1310

11+
if !isdefined(Base, :get_extension)
12+
include("../ext/AbstractFFTsChainRulesCoreExt.jl")
13+
end
14+
1415
end # module

src/definitions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ _to1(::Tuple, x) = copy1(eltype(x), x)
5959
for f in (:fft, :bfft, :ifft, :fft!, :bfft!, :ifft!, :rfft)
6060
pf = Symbol("plan_", f)
6161
@eval begin
62-
$f(x::AbstractArray) = (y = to1(x); $pf(y) * y)
62+
$f(x::AbstractArray) = $f(x, 1:ndims(x))
6363
$f(x::AbstractArray, region) = (y = to1(x); $pf(y, region) * y)
6464
$pf(x::AbstractArray; kws...) = (y = to1(x); $pf(y, 1:ndims(y); kws...))
6565
end
@@ -207,9 +207,9 @@ bfft!
207207
for f in (:fft, :bfft, :ifft)
208208
pf = Symbol("plan_", f)
209209
@eval begin
210-
$f(x::AbstractArray{<:Real}, region=1:ndims(x)) = $f(complexfloat(x), region)
210+
$f(x::AbstractArray{<:Real}, region) = $f(complexfloat(x), region)
211211
$pf(x::AbstractArray{<:Real}, region; kws...) = $pf(complexfloat(x), region; kws...)
212-
$f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, region=1:ndims(x)) = $f(complexfloat(x), region)
212+
$f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, region) = $f(complexfloat(x), region)
213213
$pf(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, region; kws...) = $pf(complexfloat(x), region; kws...)
214214
end
215215
end
@@ -297,16 +297,16 @@ LinearAlgebra.mul!(y::AbstractArray, p::ScaledPlan, x::AbstractArray) =
297297
for f in (:brfft, :irfft)
298298
pf = Symbol("plan_", f)
299299
@eval begin
300-
$f(x::AbstractArray, d::Integer) = $pf(x, d) * x
300+
$f(x::AbstractArray, d::Integer) = $f(x, d, 1:ndims(x))
301301
$f(x::AbstractArray, d::Integer, region) = $pf(x, d, region) * x
302302
$pf(x::AbstractArray, d::Integer;kws...) = $pf(x, d, 1:ndims(x);kws...)
303303
end
304304
end
305305

306306
for f in (:brfft, :irfft)
307307
@eval begin
308-
$f(x::AbstractArray{<:Real}, d::Integer, region=1:ndims(x)) = $f(complexfloat(x), d, region)
309-
$f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, d::Integer, region=1:ndims(x)) = $f(complexfloat(x), d, region)
308+
$f(x::AbstractArray{<:Real}, d::Integer, region) = $f(complexfloat(x), d, region)
309+
$f(x::AbstractArray{<:Complex{<:Union{Integer,Rational}}}, d::Integer, region) = $f(complexfloat(x), d, region)
310310
end
311311
end
312312

test/runtests.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,33 @@ end
115115
@test @inferred(f9(plan_fft(zeros(10), 1), 10)) == 1/10
116116
end
117117

118+
# Test that dims defaults to 1:ndims for fft-like functions
119+
@testset "Default dims" begin
120+
for x in (randn(3), randn(3, 4), randn(3, 4, 5))
121+
N = ndims(x)
122+
complex_x = complex.(x)
123+
@test fft(x) fft(x, 1:N)
124+
@test ifft(x) ifft(x, 1:N)
125+
@test bfft(x) bfft(x, 1:N)
126+
@test rfft(x) rfft(x, 1:N)
127+
d = 2 * size(x, 1) - 1
128+
@test irfft(x, d) irfft(x, d, 1:N)
129+
@test brfft(x, d) brfft(x, d, 1:N)
130+
end
131+
end
132+
133+
@testset "Complex float promotion" begin
134+
for x in (rand(-5:5, 3), rand(-5:5, 3, 4), rand(-5:5, 3, 4, 5))
135+
N = ndims(x)
136+
@test fft(x) fft(complex.(x)) fft(complex.(float.(x)))
137+
@test ifft(x) ifft(complex.(x)) ifft(complex.(float.(x)))
138+
@test bfft(x) bfft(complex.(x)) bfft(complex.(float.(x)))
139+
d = 2 * size(x, 1) - 1
140+
@test irfft(x, d) irfft(complex.(x), d) irfft(complex.(float.(x)), d)
141+
@test brfft(x, d) brfft(complex.(x), d) brfft(complex.(float.(x)), d)
142+
end
143+
end
144+
118145
@testset "ChainRules" begin
119146
@testset "shift functions" begin
120147
for x in (randn(3), randn(3, 4), randn(3, 4, 5))

0 commit comments

Comments
 (0)