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,
3
+ MappedBasisLayout, AdjointMappedBasisLayout, MappedWeightedBasisLayout, igetindex, TransformFactorization, Weight, WeightedBasisLayout, SubWeightedBasisLayout, WeightLayout,
4
4
Expansion, basis
5
5
import QuasiArrays: SubQuasiArray, MulQuasiMatrix, Vec, Inclusion, QuasiDiagonal, LazyQuasiArrayApplyStyle, LazyQuasiArrayStyle
6
6
import LazyArrays: MemoryLayout, ApplyStyle, Applied, colsupport, arguments, ApplyLayout, LdivStyle, MulStyle
236
236
L = LinearSpline ([1 ,2 ,3 ])
237
237
f = L* [1 ,2 ,4 ]
238
238
g = L* [5 ,6 ,7 ]
239
-
239
+
240
240
@test f isa Expansion
241
241
@test 2 f isa Expansion
242
242
@test f* 2 isa Expansion
346
346
@testset " sub-colon" begin
347
347
L = LinearSpline ([1 ,2 ,3 ])
348
348
@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 ]
350
350
end
351
351
352
352
@testset " transform" begin
459
459
@testset " diff" begin
460
460
L = LinearSpline (range (- 1 ,stop= 1 ,length= 10 ))
461
461
f = L * randn (size (L,2 ))
462
- h = 0.0001 ;
462
+ h = 0.0001 ;
463
463
@test diff (f)[0.1 ] ≈ (f[0.1 + h]- f[0.1 ])/ h
464
464
end
465
465
485
485
486
486
struct ChebyshevWeight <: Weight{Float64} end
487
487
488
-
488
+ Base.:( == )( :: Chebyshev , :: Chebyshev ) = true
489
489
Base. axes (T:: Chebyshev ) = (Inclusion (- 1 .. 1 ), Base. OneTo (T. n))
490
490
ContinuumArrays. grid (T:: Chebyshev ) = chebyshevpoints (Float64, T. n, Val (1 ))
491
491
Base. axes (T:: ChebyshevWeight ) = (Inclusion (- 1 .. 1 ),)
@@ -496,33 +496,49 @@ Base.getindex(::ChebyshevWeight, x::Float64) = 1/sqrt(1-x^2)
496
496
LinearAlgebra. factorize (L:: Chebyshev ) =
497
497
TransformFactorization (grid (L), plan_chebyshevtransform (Array {Float64} (undef, size (L,2 ))))
498
498
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
+
499
502
@testset " Chebyshev" begin
500
503
T = Chebyshev (5 )
504
+ w = ChebyshevWeight ()
505
+ wT = w .* T
501
506
x = axes (T,1 )
502
507
F = factorize (T)
503
508
g = grid (F)
504
509
@test T \ exp .(x) == F \ exp .(x) == F \ exp .(g) == chebyshevtransform (exp .(g), Val (1 ))
505
510
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
517
514
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)
521
521
522
+ @test ContinuumArrays. unweightedbasis (wT) ≡ T
523
+ @test ContinuumArrays. unweightedbasis (wT2) ≡ T[:,2 : 4 ]
524
+ @test ContinuumArrays. unweightedbasis (wT3) ≡ T[:,2 : 4 ]
525
+ end
522
526
@testset " Mapped" begin
523
527
y = affine (0 .. 1 , x)
524
528
@test MemoryLayout (wT[y,:]) isa MappedWeightedBasisLayout
525
529
@test MemoryLayout (w[y] .* T[y,:]) isa MappedWeightedBasisLayout
526
530
@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 ],:]
527
531
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
528
544
end
0 commit comments