diff --git a/test/test_ChangeBasis.jl b/test/test_ChangeBasis.jl index 13986ae53..a254dee4e 100644 --- a/test/test_ChangeBasis.jl +++ b/test/test_ChangeBasis.jl @@ -1,20 +1,30 @@ @testset "ChangeBasis" begin ε = 1e-13 function test_changebasis_R(P,P′) + # The test case must hold P ⊆ P′ @test P ⊆ P′ - A = @inferred changebasis(P,P′) + # Test type stability + A = @inferred changebasis_R(P,P′) + # Test output type @test A isa SparseMatrixCSC + # Zeros must not be stored @test !any(iszero.(A.nzval)) - @test A == BasicBSpline._changebasis_R(P,P′) == changebasis_R(P,P′) + # Test the size of A n = dim(P) n′ = dim(P′) @test size(A) == (n,n′) + # Elements must not be stored for degenerate row/col + for j in 1:n′ + @test any(Base.isstored.(Ref(A), 1:n, j)) == isnondegenerate_R(P′, j) + end + for i in 1:n + @test any(Base.isstored.(Ref(A), i, 1:n′)) == isnondegenerate_R(P, i) + end + # B_{(i,p,k)} = ∑ⱼ A_{i,j} B_{(j,p′,k′)} ts = range(extrema(knotvector(P)+knotvector(P′))..., length=20) for t in ts @test norm(bsplinebasis.(P,1:n,t) - A*bsplinebasis.(P′,1:n′,t), Inf) < ε end - @test iszero(view(A, findall(BasicBSpline._iszeros_R(P)), :)) - @test iszero(view(A, :, findall(BasicBSpline._iszeros_R(P′)))) end function test_changebasis_I(P1, P2; check_zero=true) @@ -123,13 +133,14 @@ _P8 = BSplineSpace{3, Int64, KnotVector{Int64}}(KnotVector(-[1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 7, 7])) test_changebasis_I(_P7, _P8) + # (2,2)-element is stored, but it is zero. Q1 = BSplineSpace{1, Int64, KnotVector{Int64}}(KnotVector([2, 2, 4, 4, 6, 6])) Q2 = BSplineSpace{3, Int64, KnotVector{Int64}}(KnotVector([1, 1, 1, 2, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7])) test_changebasis_I(Q1, Q2; check_zero=false) Q3 = BSplineSpace{4, Int64, KnotVector{Int64}}(KnotVector([1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 7])) Q4 = BSplineSpace{5, Int64, KnotVector{Int64}}(KnotVector([1, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 5, 6])) - test_changebasis_I(Q3, Q4; check_zero=false) + test_changebasis_I(Q3, Q4) end @testset "changebasis_sim" begin