Skip to content

Commit 6fe969e

Browse files
authored
Convert ApproxFunBaseTest to a package extension (#657)
* Convert ApproxFunBaseTest to a package extension * Add comment * Ignore Test in downgrade job
1 parent a0b01af commit 6fe969e

File tree

8 files changed

+307
-3
lines changed

8 files changed

+307
-3
lines changed

.github/workflows/CompatHelper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: "Run CompatHelper"
3838
run: |
3939
import CompatHelper
40-
CompatHelper.main(; subdirs=["", "ApproxFunBaseTest"])
40+
CompatHelper.main()
4141
shell: julia --color=yes {0}
4242
env:
4343
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/downgrade.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ jobs:
4545
version: ${{ matrix.version }}
4646
- uses: cjdoris/julia-downgrade-compat-action@v1
4747
with:
48-
skip: LinearAlgebra,SparseArrays,Statistics
48+
skip: LinearAlgebra,SparseArrays,Statistics,Test
4949
- uses: julia-actions/julia-buildpkg@v1
5050
- uses: julia-actions/julia-runtest@v1

.github/workflows/downstream.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
try
6464
# force it to use this PR's version of the package
6565
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
66-
Pkg.develop(PackageSpec(path="ApproxFunBaseTest"))
6766
Pkg.update()
6867
Pkg.test(; coverage = "@src") # resolver may fail with test time deps
6968
catch err

ApproxFunBaseTest/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This package is now deprecated in favor of a package extension at `ext/ApproxFunBaseTestExt.jl`

Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2424
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2525
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2626

27+
[weakdeps]
28+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
29+
30+
[extensions]
31+
ApproxFunBaseTestExt = "Test"
32+
2733
[compat]
2834
AbstractFFTs = "0.5, 1"
2935
Aqua = "0.8"

ext/ApproxFunBaseTestExt.jl

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
module ApproxFunBaseTestExt
2+
3+
using ApproxFunBase
4+
using Test
5+
using ApproxFunBase: plan_transform, plan_itransform, israggedbelow, RaggedMatrix, isbandedbelow, isbanded,
6+
blockstart, blockstop, resizedata!
7+
using ApproxFunBase.BandedMatrices: BandedMatrices, rowstart, rowstop, colstart, colstop, BandedMatrix, bandwidth
8+
using ApproxFunBase.BlockArrays: blockrowstop, blockcolstop, Block
9+
using ApproxFunBase.BlockBandedMatrices: isbandedblockbanded, blockbandwidth, isblockbanded, subblockbandwidth
10+
using ApproxFunBase.DomainSets: dimension
11+
using ApproxFunBase.InfiniteArrays
12+
using ApproxFunBase.LinearAlgebra
13+
14+
import ApproxFunBase.TestUtils: testspace, testfunctional, testraggedbelowoperator, testbandedblockbandedoperator,
15+
testbandedoperator, testtransforms, testcalculus, testmultiplication, testinfoperator,
16+
testblockbandedoperator, testbandedbelowoperator
17+
18+
# assert type in convert
19+
strictconvert(::Type{T}, x) where {T} = convert(T, x)::T
20+
21+
## Spaces Tests
22+
23+
24+
function testtransforms(S::Space;minpoints=1,invertibletransform=true)
25+
# transform tests
26+
v = rand(max(minpoints,min(100,dimension(S))))
27+
plan = plan_transform(S,v)
28+
@test transform(S,v) == plan*v
29+
30+
iplan = plan_itransform(S,v)
31+
@test itransform(S,v) == iplan*v
32+
33+
if invertibletransform
34+
for k=max(1,minpoints):min(5,dimension(S))
35+
v = [zeros(k-1);1.0]
36+
@test transform(S,itransform(S,v)) v
37+
end
38+
39+
@test transform(S,itransform(S,v)) v
40+
@test itransform(S,transform(S,v)) v
41+
end
42+
end
43+
44+
function testcalculus(S::Space;haslineintegral=true,hasintegral=true)
45+
@testset for k=1:min(5,dimension(S))
46+
v = [zeros(k-1);1.0]
47+
f = Fun(S,v)
48+
@test abs(DefiniteIntegral()*f-sum(f)) < 100eps()
49+
if haslineintegral
50+
@test DefiniteLineIntegral()*f linesum(f)
51+
end
52+
@test norm(Derivative()*f-f') < 100eps()
53+
if hasintegral
54+
@test norm(differentiate(integrate(f))-f) < 100eps()
55+
@test norm(differentiate(cumsum(f))-f) < 200eps()
56+
@test norm(first(cumsum(f))) < 100eps()
57+
end
58+
end
59+
end
60+
61+
function testmultiplication(spa,spb)
62+
@testset for k=1:10
63+
a = Fun(spa,[zeros(k-1);1.])
64+
M = Multiplication(a,spb)
65+
pts = ApproxFunBase.checkpoints(rangespace(M))
66+
for j=1:10
67+
b = Fun(spb,[zeros(j-1);1.])
68+
@test (M*b).(pts) a.(pts).*b.(pts)
69+
end
70+
end
71+
end
72+
73+
function testspace(S::Space;
74+
minpoints=1,invertibletransform=true,haslineintegral=true,hasintegral=true,
75+
dualspace=S)
76+
testtransforms(S;minpoints=minpoints,invertibletransform=invertibletransform)
77+
testcalculus(S;haslineintegral=haslineintegral,hasintegral=hasintegral)
78+
if dualspace nothing
79+
testmultiplication(dualspace,S)
80+
end
81+
end
82+
83+
84+
85+
86+
87+
## Operator Tests
88+
89+
function backend_testfunctional(A)
90+
@test rowstart(A,1) 1
91+
@test colstop(A,1) 1
92+
@test bandwidth(A,1) 0
93+
@test blockbandwidth(A,1) 0
94+
95+
B=A[1:10]
96+
@test eltype(B) == eltype(A)
97+
for k=1:5
98+
@test B[k] A[k]
99+
@test isa(A[k],eltype(A))
100+
end
101+
@test isa(A[1,1:10],Vector)
102+
@test isa(A[1:1,1:10],AbstractMatrix)
103+
@test B A[1,1:10]
104+
@test transpose(B) A[1:1,1:10]
105+
@test B[3:10] A[3:10]
106+
@test B [A[k] for k=1:10]
107+
108+
109+
110+
co=cache(A)
111+
@test co[1:10] A[1:10]
112+
@test co[1:10] A[1:10]
113+
@test co[20:30] A[1:30][20:30] A[20:30]
114+
end
115+
116+
# Check that the tests pass after conversion as well
117+
function testfunctional(A::Operator{T}) where T<:Real
118+
backend_testfunctional(A)
119+
backend_testfunctional(Operator{Float64}(A))
120+
backend_testfunctional(Operator{Float32}(A))
121+
backend_testfunctional(Operator{ComplexF64}(A))
122+
end
123+
124+
function testfunctional(A::Operator{T}) where T<:Complex
125+
backend_testfunctional(A)
126+
backend_testfunctional(Operator{ComplexF32}(A))
127+
backend_testfunctional(Operator{ComplexF64}(A))
128+
end
129+
130+
function backend_testinfoperator(A)
131+
@test isinf(size(A,1))
132+
@test isinf(size(A,2))
133+
B=A[1:5,1:5]
134+
@test eltype(B) == eltype(A)
135+
136+
for k=1:5,j=1:5
137+
@test B[k,j] A[k,j]
138+
@test isa(A[k,j],eltype(A))
139+
end
140+
141+
A10 = A[1:10,1:10]
142+
A10m = Matrix(A10)
143+
A10_510 = A10m[5:10,5:10]
144+
A30 = A[1:30,1:30]
145+
A30_2030 = A30[20:30,20:30]
146+
A30_2030m = Matrix(A30_2030)
147+
148+
@test Matrix(B[2:5,1:5]) Matrix(A[2:5,1:5])
149+
@test Matrix(A[1:5,2:5]) Matrix(B[:,2:end])
150+
@test A10_510 [A[k,j] for k=5:10,j=5:10]
151+
@test A10_510 Matrix(A[5:10,5:10])
152+
@test A30_2030m Matrix(A[20:30,20:30])
153+
154+
@test Matrix(A[Block(1):Block(3),Block(1):Block(3)]) Matrix(A[blockstart(rangespace(A),1):blockstop(rangespace(A),3),blockstart(domainspace(A),1):blockstop(domainspace(A),3)])
155+
@test Matrix(A[Block(3):Block(4),Block(2):Block(4)]) Matrix(A[blockstart(rangespace(A),3):blockstop(rangespace(A),4),blockstart(domainspace(A),2):blockstop(domainspace(A),4)])
156+
157+
for k=1:10
158+
@test isfinite(colstart(A,k)) && colstart(A,k) > 0
159+
@test isfinite(rowstart(A,k)) && colstart(A,k) > 0
160+
end
161+
162+
co=cache(A)
163+
@test Matrix(co[1:10,1:10]) A10m
164+
@test Matrix(co[20:30,20:30]) A30_2030m
165+
166+
let C=cache(A)
167+
resizedata!(C,5,35)
168+
resizedata!(C,10,35)
169+
@test Matrix(C.data[1:10,1:C.datasize[2]]) Matrix(A[1:10,1:C.datasize[2]])
170+
end
171+
end
172+
173+
# Check that the tests pass after conversion as well
174+
function testinfoperator(A::Operator{T}) where T<:Real
175+
backend_testinfoperator(A)
176+
if T != Float64
177+
B = strictconvert(Operator{Float64}, A)
178+
backend_testinfoperator(B)
179+
end
180+
if T != Float32
181+
B = strictconvert(Operator{Float32}, A)
182+
backend_testinfoperator(B)
183+
end
184+
B = strictconvert(Operator{ComplexF64}, A)
185+
backend_testinfoperator(B)
186+
end
187+
188+
function testinfoperator(A::Operator{T}) where T<:Complex
189+
backend_testinfoperator(A)
190+
if T != ComplexF32
191+
backend_testinfoperator(strictconvert(Operator{ComplexF32}, A))
192+
end
193+
if T != ComplexF64
194+
backend_testinfoperator(strictconvert(Operator{ComplexF64}, A))
195+
end
196+
end
197+
198+
function testraggedbelowoperator(A)
199+
@test israggedbelow(A)
200+
for k=1:20
201+
@test isfinite(colstop(A,k))
202+
end
203+
204+
R = RaggedMatrix(view(A, 1:10, 1:min(10,size(A,2))))
205+
for j=1:size(R,2)
206+
@test colstop(R,j) == min(colstop(A,j),10)
207+
end
208+
209+
testinfoperator(A)
210+
end
211+
212+
function testbandedbelowoperator(A)
213+
@test isbandedbelow(A)
214+
@test isfinite(bandwidth(A,1))
215+
testraggedbelowoperator(A)
216+
217+
for k=1:10
218+
@test colstop(A,k) max(0,k + bandwidth(A,1))
219+
end
220+
end
221+
222+
223+
function testalmostbandedoperator(A)
224+
testbandedbelowoperator(A)
225+
end
226+
227+
function testbandedoperator(A)
228+
@test isbanded(A)
229+
@test isfinite(bandwidth(A,2))
230+
testalmostbandedoperator(A)
231+
for k=1:10
232+
@test rowstop(A,k) k + bandwidth(A,2)
233+
end
234+
235+
Am = A[1:10,1:10]
236+
@test Am isa AbstractMatrix && BandedMatrices.isbanded(Am)
237+
end
238+
239+
240+
function testblockbandedoperator(A)
241+
@test isblockbanded(A)
242+
testraggedbelowoperator(A)
243+
@test isfinite(blockbandwidth(A,2))
244+
@test isfinite(blockbandwidth(A,1))
245+
246+
247+
if -blockbandwidth(A,1) blockbandwidth(A,2)
248+
for K=1:10
249+
@test K - blockbandwidth(A,2) blockcolstop(A,Block(K)).n[1] K + blockbandwidth(A,1) <
250+
@test K - blockbandwidth(A,1) blockrowstop(A,Block(K)).n[1] K + blockbandwidth(A,2) <
251+
end
252+
end
253+
end
254+
255+
function testbandedblockbandedoperator(A)
256+
@test isbandedblockbanded(A)
257+
testblockbandedoperator(A)
258+
@test isfinite(subblockbandwidth(A,1))
259+
@test isfinite(subblockbandwidth(A,2))
260+
261+
Am = A[Block.(1:4),Block.(1:4)]
262+
@test Am isa AbstractMatrix && isbandedblockbanded(Am)
263+
end
264+
265+
266+
end

src/ApproxFunBase.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,6 @@ include("eigen.jl")
166166
include("hacks.jl")
167167
include("specialfunctions.jl")
168168
include("show.jl")
169+
include("testutils.jl")
169170

170171
end #module

src/testutils.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module TestUtils
2+
3+
# methods to the functions defined here are added in ext/ApproxFunBaseTestExt.jl
4+
5+
export testspace, testfunctional, testraggedbelowoperator, testbandedblockbandedoperator,
6+
testbandedoperator, testtransforms, testcalculus, testmultiplication, testinfoperator,
7+
testblockbandedoperator, testbandedbelowoperator
8+
9+
function testspace end
10+
11+
function testfunctional end
12+
13+
function testraggedbelowoperator end
14+
15+
function testbandedblockbandedoperator end
16+
17+
function testbandedoperator end
18+
19+
function testtransforms end
20+
21+
function testcalculus end
22+
23+
function testmultiplication end
24+
25+
function testinfoperator end
26+
27+
function testblockbandedoperator end
28+
29+
function testbandedbelowoperator end
30+
31+
end

0 commit comments

Comments
 (0)