Skip to content

Convert ApproxFunBaseTest to a package extension #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: "Run CompatHelper"
run: |
import CompatHelper
CompatHelper.main(; subdirs=["", "ApproxFunBaseTest"])
CompatHelper.main()
shell: julia --color=yes {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/downgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ jobs:
version: ${{ matrix.version }}
- uses: cjdoris/julia-downgrade-compat-action@v1
with:
skip: LinearAlgebra,SparseArrays,Statistics
skip: LinearAlgebra,SparseArrays,Statistics,Test
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
1 change: 0 additions & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
try
# force it to use this PR's version of the package
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
Pkg.develop(PackageSpec(path="ApproxFunBaseTest"))
Pkg.update()
Pkg.test(; coverage = "@src") # resolver may fail with test time deps
catch err
Expand Down
1 change: 1 addition & 0 deletions ApproxFunBaseTest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This package is now deprecated in favor of a package extension at `ext/ApproxFunBaseTestExt.jl`
6 changes: 6 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[weakdeps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[extensions]
ApproxFunBaseTestExt = "Test"

[compat]
AbstractFFTs = "0.5, 1"
Aqua = "0.8"
Expand Down
266 changes: 266 additions & 0 deletions ext/ApproxFunBaseTestExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
module ApproxFunBaseTestExt

using ApproxFunBase
using Test
using ApproxFunBase: plan_transform, plan_itransform, israggedbelow, RaggedMatrix, isbandedbelow, isbanded,
blockstart, blockstop, resizedata!
using ApproxFunBase.BandedMatrices: BandedMatrices, rowstart, rowstop, colstart, colstop, BandedMatrix, bandwidth
using ApproxFunBase.BlockArrays: blockrowstop, blockcolstop, Block
using ApproxFunBase.BlockBandedMatrices: isbandedblockbanded, blockbandwidth, isblockbanded, subblockbandwidth
using ApproxFunBase.DomainSets: dimension
using ApproxFunBase.InfiniteArrays
using ApproxFunBase.LinearAlgebra

import ApproxFunBase.TestUtils: testspace, testfunctional, testraggedbelowoperator, testbandedblockbandedoperator,
testbandedoperator, testtransforms, testcalculus, testmultiplication, testinfoperator,
testblockbandedoperator, testbandedbelowoperator

# assert type in convert
strictconvert(::Type{T}, x) where {T} = convert(T, x)::T

Check warning on line 19 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L19

Added line #L19 was not covered by tests

## Spaces Tests


function testtransforms(S::Space;minpoints=1,invertibletransform=true)

Check warning on line 24 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L24

Added line #L24 was not covered by tests
# transform tests
v = rand(max(minpoints,min(100,dimension(S))))
plan = plan_transform(S,v)
@test transform(S,v) == plan*v

Check warning on line 28 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L26-L28

Added lines #L26 - L28 were not covered by tests

iplan = plan_itransform(S,v)
@test itransform(S,v) == iplan*v

Check warning on line 31 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L30-L31

Added lines #L30 - L31 were not covered by tests

if invertibletransform
for k=max(1,minpoints):min(5,dimension(S))
v = [zeros(k-1);1.0]
@test transform(S,itransform(S,v)) ≈ v
end

Check warning on line 37 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L33-L37

Added lines #L33 - L37 were not covered by tests

@test transform(S,itransform(S,v)) ≈ v
@test itransform(S,transform(S,v)) ≈ v

Check warning on line 40 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L39-L40

Added lines #L39 - L40 were not covered by tests
end
end

function testcalculus(S::Space;haslineintegral=true,hasintegral=true)
@testset for k=1:min(5,dimension(S))
v = [zeros(k-1);1.0]
f = Fun(S,v)
@test abs(DefiniteIntegral()*f-sum(f)) < 100eps()
if haslineintegral
@test DefiniteLineIntegral()*f ≈ linesum(f)

Check warning on line 50 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L44-L50

Added lines #L44 - L50 were not covered by tests
end
@test norm(Derivative()*f-f') < 100eps()
if hasintegral
@test norm(differentiate(integrate(f))-f) < 100eps()
@test norm(differentiate(cumsum(f))-f) < 200eps()
@test norm(first(cumsum(f))) < 100eps()

Check warning on line 56 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L52-L56

Added lines #L52 - L56 were not covered by tests
end
end

Check warning on line 58 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L58

Added line #L58 was not covered by tests
end

function testmultiplication(spa,spb)
@testset for k=1:10
a = Fun(spa,[zeros(k-1);1.])
M = Multiplication(a,spb)
pts = ApproxFunBase.checkpoints(rangespace(M))
for j=1:10
b = Fun(spb,[zeros(j-1);1.])
@test (M*b).(pts) ≈ a.(pts).*b.(pts)
end
end

Check warning on line 70 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L61-L70

Added lines #L61 - L70 were not covered by tests
end

function testspace(S::Space;

Check warning on line 73 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L73

Added line #L73 was not covered by tests
minpoints=1,invertibletransform=true,haslineintegral=true,hasintegral=true,
dualspace=S)
testtransforms(S;minpoints=minpoints,invertibletransform=invertibletransform)
testcalculus(S;haslineintegral=haslineintegral,hasintegral=hasintegral)
if dualspace ≠ nothing
testmultiplication(dualspace,S)

Check warning on line 79 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L76-L79

Added lines #L76 - L79 were not covered by tests
end
end





## Operator Tests

function backend_testfunctional(A)
@test rowstart(A,1) ≥ 1
@test colstop(A,1) ≤ 1
@test bandwidth(A,1) ≤ 0
@test blockbandwidth(A,1) ≤ 0

Check warning on line 93 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L89-L93

Added lines #L89 - L93 were not covered by tests

B=A[1:10]
@test eltype(B) == eltype(A)
for k=1:5
@test B[k] ≈ A[k]
@test isa(A[k],eltype(A))
end
@test isa(A[1,1:10],Vector)
@test isa(A[1:1,1:10],AbstractMatrix)
@test B ≈ A[1,1:10]
@test transpose(B) ≈ A[1:1,1:10]
@test B[3:10] ≈ A[3:10]
@test B ≈ [A[k] for k=1:10]

Check warning on line 106 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L95-L106

Added lines #L95 - L106 were not covered by tests



co=cache(A)
@test co[1:10] ≈ A[1:10]
@test co[1:10] ≈ A[1:10]
@test co[20:30] ≈ A[1:30][20:30] ≈ A[20:30]

Check warning on line 113 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L110-L113

Added lines #L110 - L113 were not covered by tests
end

# Check that the tests pass after conversion as well
function testfunctional(A::Operator{T}) where T<:Real
backend_testfunctional(A)
backend_testfunctional(Operator{Float64}(A))
backend_testfunctional(Operator{Float32}(A))
backend_testfunctional(Operator{ComplexF64}(A))

Check warning on line 121 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L117-L121

Added lines #L117 - L121 were not covered by tests
end

function testfunctional(A::Operator{T}) where T<:Complex
backend_testfunctional(A)
backend_testfunctional(Operator{ComplexF32}(A))
backend_testfunctional(Operator{ComplexF64}(A))

Check warning on line 127 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L124-L127

Added lines #L124 - L127 were not covered by tests
end

function backend_testinfoperator(A)
@test isinf(size(A,1))
@test isinf(size(A,2))
B=A[1:5,1:5]
@test eltype(B) == eltype(A)

Check warning on line 134 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L130-L134

Added lines #L130 - L134 were not covered by tests

for k=1:5,j=1:5
@test B[k,j] ≈ A[k,j]
@test isa(A[k,j],eltype(A))
end

Check warning on line 139 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L136-L139

Added lines #L136 - L139 were not covered by tests

A10 = A[1:10,1:10]
A10m = Matrix(A10)
A10_510 = A10m[5:10,5:10]
A30 = A[1:30,1:30]
A30_2030 = A30[20:30,20:30]
A30_2030m = Matrix(A30_2030)

Check warning on line 146 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L141-L146

Added lines #L141 - L146 were not covered by tests

@test Matrix(B[2:5,1:5]) ≈ Matrix(A[2:5,1:5])
@test Matrix(A[1:5,2:5]) ≈ Matrix(B[:,2:end])
@test A10_510 ≈ [A[k,j] for k=5:10,j=5:10]
@test A10_510 ≈ Matrix(A[5:10,5:10])
@test A30_2030m ≈ Matrix(A[20:30,20:30])

Check warning on line 152 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L148-L152

Added lines #L148 - L152 were not covered by tests

@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)])
@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)])

Check warning on line 155 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L154-L155

Added lines #L154 - L155 were not covered by tests

for k=1:10
@test isfinite(colstart(A,k)) && colstart(A,k) > 0
@test isfinite(rowstart(A,k)) && colstart(A,k) > 0
end

Check warning on line 160 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L157-L160

Added lines #L157 - L160 were not covered by tests

co=cache(A)
@test Matrix(co[1:10,1:10]) ≈ A10m
@test Matrix(co[20:30,20:30]) ≈ A30_2030m

Check warning on line 164 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L162-L164

Added lines #L162 - L164 were not covered by tests

let C=cache(A)
resizedata!(C,5,35)
resizedata!(C,10,35)
@test Matrix(C.data[1:10,1:C.datasize[2]]) ≈ Matrix(A[1:10,1:C.datasize[2]])

Check warning on line 169 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L166-L169

Added lines #L166 - L169 were not covered by tests
end
end

# Check that the tests pass after conversion as well
function testinfoperator(A::Operator{T}) where T<:Real
backend_testinfoperator(A)
if T != Float64
B = strictconvert(Operator{Float64}, A)
backend_testinfoperator(B)

Check warning on line 178 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L174-L178

Added lines #L174 - L178 were not covered by tests
end
if T != Float32
B = strictconvert(Operator{Float32}, A)
backend_testinfoperator(B)

Check warning on line 182 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L180-L182

Added lines #L180 - L182 were not covered by tests
end
B = strictconvert(Operator{ComplexF64}, A)
backend_testinfoperator(B)

Check warning on line 185 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L184-L185

Added lines #L184 - L185 were not covered by tests
end

function testinfoperator(A::Operator{T}) where T<:Complex
backend_testinfoperator(A)
if T != ComplexF32
backend_testinfoperator(strictconvert(Operator{ComplexF32}, A))

Check warning on line 191 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L188-L191

Added lines #L188 - L191 were not covered by tests
end
if T != ComplexF64
backend_testinfoperator(strictconvert(Operator{ComplexF64}, A))

Check warning on line 194 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L193-L194

Added lines #L193 - L194 were not covered by tests
end
end

function testraggedbelowoperator(A)
@test israggedbelow(A)
for k=1:20
@test isfinite(colstop(A,k))
end

Check warning on line 202 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L198-L202

Added lines #L198 - L202 were not covered by tests

R = RaggedMatrix(view(A, 1:10, 1:min(10,size(A,2))))
for j=1:size(R,2)
@test colstop(R,j) == min(colstop(A,j),10)
end

Check warning on line 207 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L204-L207

Added lines #L204 - L207 were not covered by tests

testinfoperator(A)

Check warning on line 209 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L209

Added line #L209 was not covered by tests
end

function testbandedbelowoperator(A)
@test isbandedbelow(A)
@test isfinite(bandwidth(A,1))
testraggedbelowoperator(A)

Check warning on line 215 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L212-L215

Added lines #L212 - L215 were not covered by tests

for k=1:10
@test colstop(A,k) ≤ max(0,k + bandwidth(A,1))
end

Check warning on line 219 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L217-L219

Added lines #L217 - L219 were not covered by tests
end


function testalmostbandedoperator(A)
testbandedbelowoperator(A)

Check warning on line 224 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L223-L224

Added lines #L223 - L224 were not covered by tests
end

function testbandedoperator(A)
@test isbanded(A)
@test isfinite(bandwidth(A,2))
testalmostbandedoperator(A)
for k=1:10
@test rowstop(A,k) ≤ k + bandwidth(A,2)
end

Check warning on line 233 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L227-L233

Added lines #L227 - L233 were not covered by tests

Am = A[1:10,1:10]
@test Am isa AbstractMatrix && BandedMatrices.isbanded(Am)

Check warning on line 236 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L235-L236

Added lines #L235 - L236 were not covered by tests
end


function testblockbandedoperator(A)
@test isblockbanded(A)
testraggedbelowoperator(A)
@test isfinite(blockbandwidth(A,2))
@test isfinite(blockbandwidth(A,1))

Check warning on line 244 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L240-L244

Added lines #L240 - L244 were not covered by tests


if -blockbandwidth(A,1) ≤ blockbandwidth(A,2)
for K=1:10
@test K - blockbandwidth(A,2) ≤ blockcolstop(A,Block(K)).n[1] ≤ K + blockbandwidth(A,1) < ∞
@test K - blockbandwidth(A,1) ≤ blockrowstop(A,Block(K)).n[1] ≤ K + blockbandwidth(A,2) < ∞
end

Check warning on line 251 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L247-L251

Added lines #L247 - L251 were not covered by tests
end
end

function testbandedblockbandedoperator(A)
@test isbandedblockbanded(A)
testblockbandedoperator(A)
@test isfinite(subblockbandwidth(A,1))
@test isfinite(subblockbandwidth(A,2))

Check warning on line 259 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L255-L259

Added lines #L255 - L259 were not covered by tests

Am = A[Block.(1:4),Block.(1:4)]
@test Am isa AbstractMatrix && isbandedblockbanded(Am)

Check warning on line 262 in ext/ApproxFunBaseTestExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ApproxFunBaseTestExt.jl#L261-L262

Added lines #L261 - L262 were not covered by tests
end


end
1 change: 1 addition & 0 deletions src/ApproxFunBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,6 @@ include("eigen.jl")
include("hacks.jl")
include("specialfunctions.jl")
include("show.jl")
include("testutils.jl")

end #module
31 changes: 31 additions & 0 deletions src/testutils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module TestUtils

# methods to the functions defined here are added in ext/ApproxFunBaseTestExt.jl

export testspace, testfunctional, testraggedbelowoperator, testbandedblockbandedoperator,
testbandedoperator, testtransforms, testcalculus, testmultiplication, testinfoperator,
testblockbandedoperator, testbandedbelowoperator

function testspace end

function testfunctional end

function testraggedbelowoperator end

function testbandedblockbandedoperator end

function testbandedoperator end

function testtransforms end

function testcalculus end

function testmultiplication end

function testinfoperator end

function testblockbandedoperator end

function testbandedbelowoperator end

end
Loading