11using ContinuumArrays, QuasiArrays, LazyArrays, IntervalSets, FillArrays, LinearAlgebra, BandedMatrices, FastTransforms, InfiniteArrays, Test, Base64
22import ContinuumArrays: ℵ₁, materialize, AffineQuasiVector, BasisLayout, AdjointBasisLayout, SubBasisLayout, ℵ₁,
3- MappedBasisLayout, AdjointMappedBasisLayout, MappedWeightedBasisLayout, igetindex, TransformFactorization, Weight, WeightedBasisLayout, SubWeightedBasisLayout, WeightLayout,
3+ MappedBasisLayout, AdjointMappedBasisLayout, MappedWeightedBasisLayout, igetindex, TransformFactorization, Weight, WeightedBasisLayout, SubWeightedBasisLayout, WeightLayout,
44 Expansion, basis
55import QuasiArrays: SubQuasiArray, MulQuasiMatrix, Vec, Inclusion, QuasiDiagonal, LazyQuasiArrayApplyStyle, LazyQuasiArrayStyle
66import LazyArrays: MemoryLayout, ApplyStyle, Applied, colsupport, arguments, ApplyLayout, LdivStyle, MulStyle
236236 L = LinearSpline ([1 ,2 ,3 ])
237237 f = L* [1 ,2 ,4 ]
238238 g = L* [5 ,6 ,7 ]
239-
239+
240240 @test f isa Expansion
241241 @test 2 f isa Expansion
242242 @test f* 2 isa Expansion
346346 @testset " sub-colon" begin
347347 L = LinearSpline ([1 ,2 ,3 ])
348348 @test L[:,1 ][1.1 ] == (L' )[1 ,:][1.1 ] == L[1.1 ,1 ]
349- @test L[:,1 : 2 ][1.1 ,:] == (L' )[1 : 2 ,:][:,1.1 ] == L[1.1 ,1 : 2 ]
349+ @test L[:,1 : 2 ][1.1 ,:] == (L' )[1 : 2 ,:][:,1.1 ] == L[1.1 ,1 : 2 ]
350350 end
351351
352352 @testset " transform" begin
459459 @testset " diff" begin
460460 L = LinearSpline (range (- 1 ,stop= 1 ,length= 10 ))
461461 f = L * randn (size (L,2 ))
462- h = 0.0001 ;
462+ h = 0.0001 ;
463463 @test diff (f)[0.1 ] ≈ (f[0.1 + h]- f[0.1 ])/ h
464464 end
465465
485485
486486struct ChebyshevWeight <: Weight{Float64} end
487487
488-
488+ Base.:( == )( :: Chebyshev , :: Chebyshev ) = true
489489Base. axes (T:: Chebyshev ) = (Inclusion (- 1 .. 1 ), Base. OneTo (T. n))
490490ContinuumArrays. grid (T:: Chebyshev ) = chebyshevpoints (Float64, T. n, Val (1 ))
491491Base. axes (T:: ChebyshevWeight ) = (Inclusion (- 1 .. 1 ),)
@@ -496,33 +496,49 @@ Base.getindex(::ChebyshevWeight, x::Float64) = 1/sqrt(1-x^2)
496496LinearAlgebra. factorize (L:: Chebyshev ) =
497497 TransformFactorization (grid (L), plan_chebyshevtransform (Array {Float64} (undef, size (L,2 ))))
498498
499+ # This is wrong but just for tests
500+ Base. broadcasted (:: LazyQuasiArrayStyle{2} , :: typeof (* ), a:: Expansion{<:Any,<:Chebyshev} , b:: Chebyshev ) = b * Matrix (I, 5 , 5 )
501+
499502@testset " Chebyshev" begin
500503 T = Chebyshev (5 )
504+ w = ChebyshevWeight ()
505+ wT = w .* T
501506 x = axes (T,1 )
502507 F = factorize (T)
503508 g = grid (F)
504509 @test T \ exp .(x) == F \ exp .(x) == F \ exp .(g) == chebyshevtransform (exp .(g), Val (1 ))
505510
506- w = ChebyshevWeight ()
507- @test MemoryLayout (w) isa WeightLayout
508- @test MemoryLayout (w[Inclusion (0 .. 1 )]) isa WeightLayout
509-
510- wT = w .* T
511- wT2 = w .* T[:,2 : 4 ]
512- wT3 = wT[:,2 : 4 ]
513- @test MemoryLayout (wT) == WeightedBasisLayout ()
514- @test MemoryLayout (wT2) == WeightedBasisLayout ()
515- @test MemoryLayout (wT3) == SubWeightedBasisLayout ()
516- @test grid (wT) == grid (wT2) == grid (wT3) == grid (T)
511+ @testset " Weighted" begin
512+ @test MemoryLayout (w) isa WeightLayout
513+ @test MemoryLayout (w[Inclusion (0 .. 1 )]) isa WeightLayout
517514
518- @test ContinuumArrays. unweightedbasis (wT) ≡ T
519- @test ContinuumArrays. unweightedbasis (wT2) ≡ T[:,2 : 4 ]
520- @test ContinuumArrays. unweightedbasis (wT3) ≡ T[:,2 : 4 ]
515+ wT2 = w .* T[:,2 : 4 ]
516+ wT3 = wT[:,2 : 4 ]
517+ @test MemoryLayout (wT) == WeightedBasisLayout ()
518+ @test MemoryLayout (wT2) == WeightedBasisLayout ()
519+ @test MemoryLayout (wT3) == SubWeightedBasisLayout ()
520+ @test grid (wT) == grid (wT2) == grid (wT3) == grid (T)
521521
522+ @test ContinuumArrays. unweightedbasis (wT) ≡ T
523+ @test ContinuumArrays. unweightedbasis (wT2) ≡ T[:,2 : 4 ]
524+ @test ContinuumArrays. unweightedbasis (wT3) ≡ T[:,2 : 4 ]
525+ end
522526 @testset " Mapped" begin
523527 y = affine (0 .. 1 , x)
524528 @test MemoryLayout (wT[y,:]) isa MappedWeightedBasisLayout
525529 @test MemoryLayout (w[y] .* T[y,:]) isa MappedWeightedBasisLayout
526530 @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 ],:]
527531 end
532+
533+ @testset " Broadcasted" begin
534+ a = 1 .+ x .+ x.^ 2
535+ # The following are wrong, just testing dispatch
536+ @test T \ (a .* T) == I
537+ @test T \ (a .* (T * (T \ a))) ≈ [2.875 , 3.5 , 2.0 , 0.5 , 0.125 ]
538+ f = exp .(x) .* a # another broadcast layout
539+ @test T \ f == F \ f
540+
541+ ã = T * (T \ a)
542+ @test T \ (ã .* ã) ≈ [1.5 ,1 ,0.5 ,0 ,0 ]
543+ end
528544end
0 commit comments