|
| 1 | +using ApproxFunOrthogonalPolynomials |
1 | 2 | using ApproxFunBase
|
2 |
| -@testset "ApproxFunOrthogonalPolynomials" begin |
3 |
| - @test (@inferred Fun()) == Fun(x->x, Chebyshev()) |
4 |
| - @test (@inferred norm(Fun())) ≈ norm(Fun(), 2) ≈ √(2/3) # √∫x^2 dx over -1..1 |
5 |
| - |
6 |
| - v = rand(4) |
7 |
| - v2 = transform(NormalizedChebyshev(), v) |
8 |
| - @test itransform(NormalizedChebyshev(), v2) ≈ v |
9 |
| - |
10 |
| - f = @inferred Fun(x->x^2, Chebyshev()) |
11 |
| - v = @inferred coefficients(f, Chebyshev(), Legendre()) |
12 |
| - @test eltype(v) == eltype(coefficients(f)) |
13 |
| - @test v ≈ coefficients(Fun(x->x^2, Legendre())) |
14 |
| - |
15 |
| - # inference check for coefficients |
16 |
| - v = @inferred coefficients(Float64[0,0,1], Chebyshev(), Ultraspherical(1)) |
17 |
| - @test v ≈ [-0.5, 0, 0.5] |
| 3 | +using Test |
| 4 | +using LinearAlgebra |
| 5 | +using StaticArrays |
| 6 | +using BandedMatrices |
| 7 | + |
| 8 | +@testset "ApproxFunBase" begin |
| 9 | + @testset "Constructor" begin |
| 10 | + @test (@inferred Fun()) == Fun(x->x, Chebyshev()) |
| 11 | + @test (@inferred norm(Fun())) ≈ norm(Fun(), 2) ≈ √(2/3) # √∫x^2 dx over -1..1 |
| 12 | + end |
| 13 | + |
| 14 | + @testset "transform" begin |
| 15 | + v = rand(4) |
| 16 | + v2 = transform(NormalizedChebyshev(), v) |
| 17 | + @test itransform(NormalizedChebyshev(), v2) ≈ v |
| 18 | + |
| 19 | + @testset "coefficients" begin |
| 20 | + f = @inferred Fun(x->x^2, Chebyshev()) |
| 21 | + v = @inferred coefficients(f, Chebyshev(), Legendre()) |
| 22 | + @test eltype(v) == eltype(coefficients(f)) |
| 23 | + @test v ≈ coefficients(Fun(x->x^2, Legendre())) |
| 24 | + |
| 25 | + # inference check for coefficients |
| 26 | + v = @inferred coefficients(Float64[0,0,1], Chebyshev(), Ultraspherical(1)) |
| 27 | + @test v ≈ [-0.5, 0, 0.5] |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + @testset "multiplication inference" begin |
| 32 | + function g2() |
| 33 | + f = Fun(0..1) |
| 34 | + f * f |
| 35 | + end |
| 36 | + y = @inferred g2()(0.1) |
| 37 | + @test y ≈ (0.1)^2 |
| 38 | + |
| 39 | + function g3() |
| 40 | + f = Fun(0..1) |
| 41 | + f * f * f |
| 42 | + end |
| 43 | + y = @inferred g3()(0.1) |
| 44 | + @test y ≈ (0.1)^3 |
| 45 | + |
| 46 | + function g4() |
| 47 | + f = Fun(0..1) |
| 48 | + f * f * f * f |
| 49 | + end |
| 50 | + y = @inferred g4()(0.1) |
| 51 | + @test y ≈ (0.1)^4 |
| 52 | + end |
| 53 | + |
| 54 | + @testset "intpow" begin |
| 55 | + @testset "Interval" begin |
| 56 | + function h(::Val{N}) where {N} |
| 57 | + f = Fun(0..1) |
| 58 | + f^N |
| 59 | + end |
| 60 | + @test (@inferred h(Val(0)))(0.1) ≈ (0.1)^0 |
| 61 | + @test (@inferred h(Val(1)))(0.1) ≈ (0.1)^1 |
| 62 | + @test (@inferred h(Val(2)))(0.1) ≈ (0.1)^2 |
| 63 | + @test (@inferred h(Val(3)))(0.1) ≈ (0.1)^3 |
| 64 | + @test (@inferred h(Val(4)))(0.1) ≈ (0.1)^4 |
| 65 | + @test h(Val(10))(0.1) ≈ (0.1)^10 rtol=1e-6 |
| 66 | + end |
| 67 | + |
| 68 | + @testset "ChebyshevInterval" begin |
| 69 | + function h(::Val{N}) where {N} |
| 70 | + f = Fun() |
| 71 | + f^N |
| 72 | + end |
| 73 | + @test (@inferred h(Val(0)))(0.1) ≈ (0.1)^0 |
| 74 | + @test (@inferred h(Val(1)))(0.1) ≈ (0.1)^1 |
| 75 | + @test (@inferred h(Val(2)))(0.1) ≈ (0.1)^2 |
| 76 | + @test (@inferred h(Val(3)))(0.1) ≈ (0.1)^3 |
| 77 | + @test (@inferred h(Val(4)))(0.1) ≈ (0.1)^4 |
| 78 | + @test h(Val(10))(0.1) ≈ (0.1)^10 rtol=1e-6 |
| 79 | + end |
| 80 | + end |
18 | 81 |
|
19 | 82 | @testset "int coeffs" begin
|
20 | 83 | f = Fun(Chebyshev(), [0,1])
|
|
0 commit comments