1
1
using ContinuumArrays, QuasiArrays, LazyArrays, IntervalSets, FillArrays, LinearAlgebra, BandedMatrices, FastTransforms, InfiniteArrays, Test, Base64
2
2
import ContinuumArrays: ℵ₁, materialize, AffineQuasiVector, BasisLayout, AdjointBasisLayout, SubBasisLayout, ℵ₁,
3
- MappedBasisLayout, AdjointMappedBasisLayout, MappedWeightedBasisLayout, igetindex, TransformFactorization, Weight, WeightedBasisLayout, SubWeightedBasisLayout, WeightLayout,
4
- Expansion, basis
3
+ MappedBasisLayout, AdjointMappedBasisLayout, MappedWeightedBasisLayout, TransformFactorization, Weight, WeightedBasisLayout, SubWeightedBasisLayout, WeightLayout,
4
+ Expansion, basis, invmap, Map
5
5
import QuasiArrays: SubQuasiArray, MulQuasiMatrix, Vec, Inclusion, QuasiDiagonal, LazyQuasiArrayApplyStyle, LazyQuasiArrayStyle
6
6
import LazyArrays: MemoryLayout, ApplyStyle, Applied, colsupport, arguments, ApplyLayout, LdivStyle, MulStyle
7
7
24
24
25
25
@testset " Inclusion" begin
26
26
x = Inclusion (- 1 .. 1 )
27
- @test x[0.1 ] === 0.1
28
- @test x[0.0 ] === 0.0
27
+ @test eltype (x) == Float64
28
+ @test x[0.1 ] ≡ 0.1
29
+ @test x[0 ] ≡ x[0.0 ] ≡ 0.0
29
30
30
31
x = Inclusion (- 1.0 .. 1 )
31
32
X = QuasiDiagonal (x)
100
101
@test_throws BoundsError a[- 3 ]
101
102
@test a[- 2 ] == first (a) == - 1
102
103
@test a[3 ] == last (a) == 1
103
- @test igetindex (a, - 0.16 ) ≈ 0.1
104
- @test igetindex (a, 1 ) == 3
105
- @test igetindex (a, - 1 ) == - 2
104
+ @test invmap (a)[ - 0.16 ] ≈ 0.1
105
+ @test invmap (a)[ 1 ] == 3
106
+ @test invmap (a)[ - 1 ] == - 2
106
107
@test union (a) == Inclusion (- 1 .. 1 )
107
108
108
109
@test affine (0 .. 1 , - 1 .. 1 ) == y
@@ -116,11 +117,11 @@ end
116
117
117
118
@testset " DiracDelta" begin
118
119
δ = DiracDelta (- 1 .. 3 )
119
- @test axes (δ) === (axes (δ,1 ),) === (Inclusion (- 1 .. 3 ),)
120
- @test size (δ) === (length (δ),) === (ℵ₁,)
121
- @test δ[1.1 ] === 0.0
122
- @test δ[0.0 ] === Inf
123
- @test Base. IndexStyle (δ) === Base. IndexLinear ()
120
+ @test axes (δ) ≡ (axes (δ,1 ),) ≡ (Inclusion (- 1 .. 3 ),)
121
+ @test size (δ) ≡ (length (δ),) ≡ (ℵ₁,)
122
+ @test δ[1.1 ] ≡ 0.0
123
+ @test δ[0.0 ] ≡ Inf
124
+ @test Base. IndexStyle (δ) ≡ Base. IndexLinear ()
124
125
125
126
@test stringmime (" text/plain" , δ) == " δ at 0.0 over Inclusion(-1..3)"
126
127
x = Inclusion (- 1 .. 1 )
@@ -131,14 +132,14 @@ end
131
132
@testset " HeavisideSpline" begin
132
133
H = HeavisideSpline ([1 ,2 ,3 ])
133
134
134
- @test axes (H) === (axes (H,1 ),axes (H,2 )) === (Inclusion (1 .. 3 ), Base. OneTo (2 ))
135
- @test size (H) === (size (H,1 ),size (H,2 )) === (ℵ₁, 2 )
135
+ @test axes (H) ≡ (axes (H,1 ),axes (H,2 )) ≡ (Inclusion (1 .. 3 ), Base. OneTo (2 ))
136
+ @test size (H) ≡ (size (H,1 ),size (H,2 )) ≡ (ℵ₁, 2 )
136
137
137
138
@test_throws BoundsError H[0.1 , 1 ]
138
- @test H[1.1 ,1 ] === H' [1 ,1.1 ] === transpose (H)[1 ,1.1 ] === 1.0
139
- @test H[2.1 ,1 ] === H' [1 ,2.1 ] === transpose (H)[1 ,2.1 ] === 0.0
140
- @test H[1.1 ,2 ] === 0.0
141
- @test H[2.1 ,2 ] === 1.0
139
+ @test H[1.1 ,1 ] ≡ H' [1 ,1.1 ] ≡ transpose (H)[1 ,1.1 ] ≡ 1.0
140
+ @test H[2.1 ,1 ] ≡ H' [1 ,2.1 ] ≡ transpose (H)[1 ,2.1 ] ≡ 0.0
141
+ @test H[1.1 ,2 ] ≡ 0.0
142
+ @test H[2.1 ,2 ] ≡ 1.0
142
143
@test_throws BoundsError H[2.1 ,3 ]
143
144
@test_throws BoundsError H' [3 ,2.1 ]
144
145
@test_throws BoundsError transpose (H)[3 ,2.1 ]
483
484
@test_throws BoundsError K[Inclusion (0 .. 0.5 ), Inclusion (0 .. 0.5 )][1 ,1 ]
484
485
end
485
486
487
+ """
488
+ This is a simple implementation of Chebyshev for testing. Use OrthogonalPolynomialsQuasi
489
+ for the real implementation.
490
+ """
491
+
492
+
486
493
struct Chebyshev <: Basis{Float64}
487
494
n:: Int
488
495
end
@@ -503,6 +510,20 @@ LinearAlgebra.factorize(L::Chebyshev) =
503
510
# This is wrong but just for tests
504
511
Base. broadcasted (:: LazyQuasiArrayStyle{2} , :: typeof (* ), a:: Expansion{<:Any,<:Chebyshev} , b:: Chebyshev ) = b * Matrix (I, 5 , 5 )
505
512
513
+ struct QuadraticMap{T} <: Map{T} end
514
+ struct InvQuadraticMap{T} <: Map{T} end
515
+
516
+ QuadraticMap () = QuadraticMap {Float64} ()
517
+ InvQuadraticMap () = InvQuadraticMap {Float64} ()
518
+
519
+ Base. getindex (:: QuadraticMap , r:: Number ) = 2 r^ 2 - 1
520
+ Base. axes (:: QuadraticMap{T} ) where T = (Inclusion (0 .. 1 ),)
521
+ Base. axes (:: InvQuadraticMap{T} ) where T = (Inclusion (- 1 .. 1 ),)
522
+ Base. getindex (d:: InvQuadraticMap , x:: Number ) = sqrt ((x+ 1 )/ 2 )
523
+ ContinuumArrays. invmap (:: QuadraticMap{T} ) where T = InvQuadraticMap {T} ()
524
+ ContinuumArrays. invmap (:: InvQuadraticMap{T} ) where T = QuadraticMap {T} ()
525
+
526
+
506
527
@testset " Chebyshev" begin
507
528
T = Chebyshev (5 )
508
529
w = ChebyshevWeight ()
@@ -536,9 +557,33 @@ Base.broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), a::Expansion{<:Any,<:Che
536
557
@test wT[y,:][[0.1 ,0.2 ],1 : 5 ] == (w[y] .* T[y,:])[[0.1 ,0.2 ],1 : 5 ] == (w .* T[:,1 : 5 ])[y,:][[0.1 ,0.2 ],:]
537
558
@test MemoryLayout (wT[y,1 : 3 ]) isa MappedWeightedBasisLayout
538
559
@test wT[y,1 : 3 ][[0.1 ,0.2 ],1 : 2 ] == wT[y[[0.1 ,0.2 ]],1 : 2 ]
560
+
561
+ @testset " QuadraticMap" begin
562
+ m = QuadraticMap ()
563
+ mi = InvQuadraticMap ()
564
+ @test 0.1 ∈ m
565
+ @test - 0.1 ∈ m
566
+ @test 2 ∉ m
567
+ @test 0.1 ∈ mi
568
+ @test - 0.1 ∉ mi
569
+
570
+ @test m[findfirst (isequal (0.1 ), m)] ≈ 0.1
571
+ @test m[findlast (isequal (0.1 ), m)] ≈ 0.1
572
+ @test m[findall (isequal (0.1 ), m)] ≈ [0.1 ]
573
+
574
+ T = Chebyshev (5 )
575
+ M = T[m,:]
576
+ @test MemoryLayout (M) isa MappedBasisLayout
577
+ @test M[0.1 ,:] ≈ T[2 * 0.1 ^ 2 - 1 ,:]
578
+ x = axes (M,1 )
579
+ @test x == Inclusion (0 .. 1 )
580
+ @test M \ exp .(x) ≈ T \ exp .(sqrt .((axes (T,1 ) .+ 1 )/ 2 ))
581
+ end
539
582
end
540
583
541
584
@testset " Broadcasted" begin
585
+ T = Chebyshev (5 )
586
+ x = axes (T,1 )
542
587
a = 1 .+ x .+ x.^ 2
543
588
# The following are wrong, just testing dispatch
544
589
@test T \ (a .* T) == I
@@ -549,4 +594,4 @@ Base.broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), a::Expansion{<:Any,<:Che
549
594
ã = T * (T \ a)
550
595
@test T \ (ã .* ã) ≈ [1.5 ,1 ,0.5 ,0 ,0 ]
551
596
end
552
- end
597
+ end
0 commit comments