Skip to content

Backport: Convert ApproxFunBaseTest to a package extension #658

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 6 commits into from
Jun 10, 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
1 change: 0 additions & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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 = true) # resolver may fail with test time deps
catch err
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ deps/deps.jl
src/Domains/.DS_Store
.DS_Store
Manifest.toml
Manifest-v*.*.toml
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`
12 changes: 10 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFunBase"
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
version = "0.8.66"
version = "0.8.67"

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

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

[extensions]
ApproxFunBaseTestExt = "Test"

[compat]
AbstractFFTs = "0.5, 1"
Aqua = "0.6"
Expand All @@ -47,12 +53,14 @@ LazyArrays = "0.20, 0.21, 0.22, 1"
LowRankMatrices = "1"
SpecialFunctions = "0.10, 1.0, 2"
StaticArrays = "0.12, 1.0"
Test = "1"
julia = "1.6"

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

[targets]
test = ["Aqua", "Random", "Infinities"]
test = ["Aqua", "Random", "Infinities", "Test"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Core functionality of ApproxFun
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
[![deps](https://juliahub.com/docs/ApproxFunBase/deps.svg)](https://juliahub.com/ui/Packages/ApproxFunBase/deO92?t=2)
[![version](https://juliahub.com/docs/ApproxFunBase/version.svg)](https://juliahub.com/ui/Packages/ApproxFunBase/deO92)
[![pkgeval](https://juliahub.com/docs/General/ApproxFunBase/stable/pkgeval.svg)](https://juliahub.com/ui/Packages/General/ApproxFunBase)
[![pkgeval](https://juliahub.com/docs/General/ApproxFunBase/stable/pkgeval.svg)](https://juliaci.github.io/NanosoldierReports/pkgeval_badges/report.html)

[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/stable)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/dev)
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

## Spaces Tests


function testtransforms(S::Space;minpoints=1,invertibletransform=true)
# transform tests
v = rand(max(minpoints,min(100,dimension(S))))
plan = plan_transform(S,v)
@test transform(S,v) == plan*v

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

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

@test transform(S,itransform(S,v)) ≈ v
@test itransform(S,transform(S,v)) ≈ v
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)
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()
end
end
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
end

function testspace(S::Space;
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)
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

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]



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

function testfunctional(A::Operator{T}) where T<:Complex
backend_testfunctional(A)
backend_testfunctional(Operator{ComplexF32}(A))
backend_testfunctional(Operator{ComplexF64}(A))
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)

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

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)

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

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

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

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

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]])
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)
end
if T != Float32
B = strictconvert(Operator{Float32}, A)
backend_testinfoperator(B)
end
B = strictconvert(Operator{ComplexF64}, A)
backend_testinfoperator(B)
end

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

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

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

testinfoperator(A)
end

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

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


function testalmostbandedoperator(A)
testbandedbelowoperator(A)
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

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


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


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
end
end

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

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


end
8 changes: 7 additions & 1 deletion src/ApproxFunBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !,
asec, cot, acot, sinh, csch, asinh, acsch,
sech, acosh, asech, tanh, coth, atanh, acoth,
sinc, cosc, log1p, log, expm1, tan,
max, min, cbrt, atan, acos, asin
max, min, cbrt, atan, acos, asin,
AbstractMatrix, AbstractVector

import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle,
broadcastable, DefaultArrayStyle, broadcasted
Expand Down Expand Up @@ -167,5 +168,10 @@ include("hacks.jl")
include("testing.jl")
include("specialfunctions.jl")
include("show.jl")
include("testutils.jl")

if !isdefined(Base, :get_extension)
include("../ext/ApproxFunBaseTestExt.jl")
end

end #module
6 changes: 3 additions & 3 deletions src/Space.jl
Original file line number Diff line number Diff line change
Expand Up @@ -707,15 +707,15 @@ basis function.

# Examples
```jldoctest
julia> Chebyshev()(2)
Fun(Chebyshev(), [0.0, 0.0, 1.0])
julia> Chebyshev()(2) == Fun(Chebyshev(), [0, 0, 1])
true
```
"""
(s::Space)(n::Integer) = basisfunction(s, n+1)
"""
(s::Space)(n::Integer, points...)

Evaluate `s(n)(points...)`
Evaluate `Fun(s, [zeros(n); 1])(points...)` efficiently without allocating the vector of coefficients.

# Examples
```jldoctest
Expand Down
Loading
Loading