@@ -58,6 +58,37 @@ Base.getindex(d::InvQuadraticMap, x::Number) = sqrt((x+1)/2)
5858ContinuumArrays. invmap(:: QuadraticMap{T} ) where T = InvQuadraticMap{T}()
5959ContinuumArrays. invmap(:: InvQuadraticMap{T} ) where T = QuadraticMap{T}()
6060
61+ struct InfMap{T} <: Map{T}
62+ s
63+ end
64+ struct InvInfMap{T} <: Map{T}
65+ s
66+ end
67+
68+ InfMap(s= 1 ) = InfMap{Float64}(s)
69+ InvInfMap(s= 1 ) = InvInfMap{Float64}(s)
70+
71+ Base. getindex(m:: InfMap , r:: Number ) = 1 - 2 / (m. s * r+ 1 )
72+ Base. axes(m:: InfMap{T} ) where T = (Inclusion(m. s * (0 .. Inf )),)
73+ Base. axes(:: InvInfMap{T} ) where T = (Inclusion(- 1 .. 1 ),)
74+ Base. getindex(m:: InvInfMap , x:: Number ) = m. s* ( 2 / (1 - x) - 1 )
75+ ContinuumArrays. invmap(m:: InfMap{T} ) where T = InvInfMap{T}(m. s)
76+ ContinuumArrays. invmap(m:: InvInfMap{T} ) where T = InfMap{T}(m. s)
77+
78+ struct BiInfMap{T} <: Map{T} end
79+ struct InvBiInfMap{T} <: Map{T} end
80+
81+ BiInfMap() = BiInfMap{Float64}()
82+ InvBiInfMap() = InvBiInfMap{Float64}()
83+
84+ Base. getindex(m:: BiInfMap , y:: Number ) = iszero(y) ? y : (- 1 + sqrt(1 + 4 y^ 2 ))/ (2 y)
85+ Base. axes(m:: BiInfMap{T} ) where T = (Inclusion(- Inf .. Inf ),)
86+ Base. axes(:: InvBiInfMap{T} ) where T = (Inclusion(- 1 .. 1 ),)
87+ Base. getindex(m:: InvBiInfMap , x:: Number ) = x/ (1 - x^ 2 )
88+ ContinuumArrays. invmap(m:: BiInfMap{T} ) where T = InvBiInfMap{T}()
89+ ContinuumArrays. invmap(m:: InvBiInfMap{T} ) where T = BiInfMap{T}()
90+
91+
6192struct FooDomain end
6293
6394struct FooBasis <: Basis{Float64} end
@@ -146,6 +177,52 @@ Base.:(==)(::FooBasis, ::FooBasis) = true
146177 @test x == Inclusion(0..1)
147178 @test M \ exp.(x) ≈ T \ exp.(sqrt.((axes(T,1) .+ 1)/2))
148179 end
180+
181+ @testset "InvMap" begin
182+ m = InfMap()
183+ mi = InvInfMap()
184+ @test 0.1 ∈ m
185+ @test -0.1 ∈ m
186+ @test 2 ∉ m
187+ @test 2 ∈ mi
188+ @test 0.1 ∈ mi
189+ @test -0.1 ∉ mi
190+
191+ @test m[findfirst(isequal(0.1), m)] ≈ 0.1
192+ @test m[findlast(isequal(0.1), m)] ≈ 0.1
193+ @test m[findall(isequal(0.1), m)] ≈ [0.1]
194+
195+ @test m[Inclusion(0..Inf)] ≡ m
196+ @test_throws BoundsError m[Inclusion(-1..1)]
197+ T = Chebyshev(5)
198+ M = T[m,:]
199+ @test MemoryLayout(M) isa MappedBasisLayout
200+ @test MemoryLayout(M[:,1:3]) isa MappedBasisLayout
201+ @test M[0.1,:] ≈ T[1-2/(0.1+1),:]
202+ x = axes(M,1)
203+ @test x == Inclusion(0..Inf)
204+ @test M \ exp.(-x) ≈ T \ exp.(-(2 ./ (1 .- axes(T,1)) .- 1))
205+
206+ f = M/M\( 1 .- exp.(-x))
207+ @test f[0.1] ≈ 1 - exp(-0.1) atol=1E-2
208+
209+ @test f[searchsortedfirst(f, 0.5)] ≈ 0.5
210+
211+ M = T[InfMap(-1),:]
212+ @test axes(M,1) == Inclusion(-Inf .. 0)
213+ x = axes(M,1)
214+ f = M/M\( exp.(x))
215+ @test f[-0.1] ≈ exp(-0.1) atol=1E-2
216+ @test f[searchsortedfirst(f, 0.5)] ≈ 0.5
217+
218+ M = T[BiInfMap(),:]
219+ @test axes(M,1) == Inclusion(-Inf .. Inf)
220+ x = axes(M,1)
221+ f = M/M\( atan.(x))
222+ @test f[-0.1] ≈ atan(-0.1) atol=1E-2
223+ @test f[0] ≈ 0 atol=1E-10
224+ @test f[searchsortedfirst(f, 0.5)] ≈ 0.5
225+ end
149226 end
150227
151228 @testset "Broadcasted" begin
@@ -173,7 +250,7 @@ Base.:(==)(::FooBasis, ::FooBasis) = true
173250 @test (2 T)' * (T* (1 : 5 )) ≈ T' *(2T*(1:5)) ≈ T' BroadcastQuasiMatrix(* , 2 , T* (1 : 5 ))
174251 @test T' * (a .* (T * (1:5))) ≈ T' * ((a .* T) * (1 : 5 ))
175252 @test T' BroadcastQuasiMatrix(*, 2, 2T) == 4*(T' T)
176-
253+
177254 @test LazyArrays. simplifiable(* , T' , T*(1:5)) == Val(true)
178255 @test LazyArrays.simplifiable(*, T' , (a .* (T * (1 : 5 )))) == Val(true )
179256 @test LazyArrays. simplifiable(* , T' , a .* T) == Val(true)
@@ -209,6 +286,6 @@ Base.:(==)(::FooBasis, ::FooBasis) = true
209286
210287 @testset " Adjoint*Basis not defined" begin
211288 @test_throws ErrorException Chebyshev(5 )' LinearSpline([- 1 ,1 ])
212- @test_throws ErrorException FooBasis()' FooBasis()
289+ @test_throws ErrorException FooBasis()' FooBasis()
213290 end
214291end
0 commit comments