@@ -595,18 +595,18 @@ end
595595 B = cholesky (A)
596596 B32 = cholesky (Float32 .(A))
597597 @test B isa Cholesky{Float16, Matrix{Float16}}
598- @test B. U isa UpperTriangular{Float16, Matrix {Float16}}
599- @test B. L isa LowerTriangular{Float16, Matrix {Float16}}
600- @test B. UL isa UpperTriangular{Float16, Matrix {Float16}}
598+ @test B. U isa UpperTriangular{Float16, <: AbstractMatrix {Float16} }
599+ @test B. L isa LowerTriangular{Float16, <: AbstractMatrix {Float16} }
600+ @test B. UL isa UpperTriangular{Float16, <: AbstractMatrix {Float16} }
601601 @test B. U ≈ B32. U
602602 @test B. L ≈ B32. L
603603 @test B. UL ≈ B32. UL
604604 @test Matrix (B) ≈ A
605605 B = cholesky (A, RowMaximum ())
606606 B32 = cholesky (Float32 .(A), RowMaximum ())
607- @test B isa CholeskyPivoted{Float16,Matrix {Float16}}
608- @test B. U isa UpperTriangular{Float16, Matrix {Float16}}
609- @test B. L isa LowerTriangular{Float16, Matrix {Float16}}
607+ @test B isa CholeskyPivoted{Float16, <: AbstractMatrix {Float16} }
608+ @test B. U isa UpperTriangular{Float16, <: AbstractMatrix {Float16} }
609+ @test B. L isa LowerTriangular{Float16, <: AbstractMatrix {Float16} }
610610 @test B. U ≈ B32. U
611611 @test B. L ≈ B32. L
612612 @test Matrix (B) ≈ A
658658 end
659659end
660660
661+ @testset " accessing both L and U factors should avoid allocations" begin
662+ n = 30
663+ A = rand (n, n)
664+ Apd = A' A
665+ allowed_cost_of_overhead = 32
666+ @assert sizeof (Apd) > 4 allowed_cost_of_overhead # ensure that we could positively identify extra copies
667+
668+ for uplo in (:L , :U )
669+ C = Symmetric (Apd, uplo)
670+ for val in (NoPivot (), RowMaximum ())
671+ B = cholesky (C, val)
672+ B. L, B. U # access once to ensure the accessor is compiled already
673+ @test (@allocated B. L) <= allowed_cost_of_overhead
674+ @test (@allocated B. U) <= allowed_cost_of_overhead
675+ end
676+ end
677+ end
678+
661679end # module TestCholesky
0 commit comments