Skip to content

Commit 2ffd207

Browse files
authored
Backport: Convert ApproxFunBaseTest to a package extension (#658)
* Backport: Convert ApproxFunBaseTest to a package extension * Bump version to v0.8.67 * Resolve dependency issues * Fix path * Backport "Update Space docstrings to not show OneElement explicitly" * Backport "Ignore versioned manifest files (#642)"
1 parent 5202e27 commit 2ffd207

File tree

11 files changed

+323
-249
lines changed

11 files changed

+323
-249
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/downstream.yml

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ deps/deps.jl
55
src/Domains/.DS_Store
66
.DS_Store
77
Manifest.toml
8+
Manifest-v*.*.toml

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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.8.66"
3+
version = "0.8.67"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -26,6 +26,12 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2626
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2727
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2828

29+
[weakdeps]
30+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
31+
32+
[extensions]
33+
ApproxFunBaseTestExt = "Test"
34+
2935
[compat]
3036
AbstractFFTs = "0.5, 1"
3137
Aqua = "0.6"
@@ -47,12 +53,14 @@ LazyArrays = "0.20, 0.21, 0.22, 1"
4753
LowRankMatrices = "1"
4854
SpecialFunctions = "0.10, 1.0, 2"
4955
StaticArrays = "0.12, 1.0"
56+
Test = "1"
5057
julia = "1.6"
5158

5259
[extras]
5360
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
5461
Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
5562
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
63+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5664

5765
[targets]
58-
test = ["Aqua", "Random", "Infinities"]
66+
test = ["Aqua", "Random", "Infinities", "Test"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Core functionality of ApproxFun
77
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
88
[![deps](https://juliahub.com/docs/ApproxFunBase/deps.svg)](https://juliahub.com/ui/Packages/ApproxFunBase/deO92?t=2)
99
[![version](https://juliahub.com/docs/ApproxFunBase/version.svg)](https://juliahub.com/ui/Packages/ApproxFunBase/deO92)
10-
[![pkgeval](https://juliahub.com/docs/General/ApproxFunBase/stable/pkgeval.svg)](https://juliahub.com/ui/Packages/General/ApproxFunBase)
10+
[![pkgeval](https://juliahub.com/docs/General/ApproxFunBase/stable/pkgeval.svg)](https://juliaci.github.io/NanosoldierReports/pkgeval_badges/report.html)
1111

1212
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/stable)
1313
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/dev)

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !,
4747
asec, cot, acot, sinh, csch, asinh, acsch,
4848
sech, acosh, asech, tanh, coth, atanh, acoth,
4949
sinc, cosc, log1p, log, expm1, tan,
50-
max, min, cbrt, atan, acos, asin
50+
max, min, cbrt, atan, acos, asin,
51+
AbstractMatrix, AbstractVector
5152

5253
import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle,
5354
broadcastable, DefaultArrayStyle, broadcasted
@@ -167,5 +168,10 @@ include("hacks.jl")
167168
include("testing.jl")
168169
include("specialfunctions.jl")
169170
include("show.jl")
171+
include("testutils.jl")
172+
173+
if !isdefined(Base, :get_extension)
174+
include("../ext/ApproxFunBaseTestExt.jl")
175+
end
170176

171177
end #module

src/Space.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,15 +707,15 @@ basis function.
707707
708708
# Examples
709709
```jldoctest
710-
julia> Chebyshev()(2)
711-
Fun(Chebyshev(), [0.0, 0.0, 1.0])
710+
julia> Chebyshev()(2) == Fun(Chebyshev(), [0, 0, 1])
711+
true
712712
```
713713
"""
714714
(s::Space)(n::Integer) = basisfunction(s, n+1)
715715
"""
716716
(s::Space)(n::Integer, points...)
717717
718-
Evaluate `s(n)(points...)`
718+
Evaluate `Fun(s, [zeros(n); 1])(points...)` efficiently without allocating the vector of coefficients.
719719
720720
# Examples
721721
```jldoctest

0 commit comments

Comments
 (0)