11module TestingTypeUtilsWithoutExtensions
2+
23using TypeUtils
34using Test
45
@@ -16,6 +17,7 @@ module TestingTypeUtils
1617
1718using TypeUtils
1819using TypeUtils: BareNumber, BIT_INTEGERS, Unsupported
20+ using LinearAlgebra
1921using Unitful
2022using OffsetArrays
2123using Test
@@ -732,6 +734,133 @@ same_value_and_type(x::T, y::T) where {T} = (x === y) || (x == y)
732734
733735 end
734736
737+ @testset " LinearAlgebra" begin
738+ A = ComplexF32 .([9 + 1im 2 - 3im 1 ; 0 7 1 ; 0 0 4 ])
739+ AAt = A* A'
740+ T = ComplexF64 # a wider type than eltype(A) for exact conversion
741+
742+ B = transpose (A)
743+ @test eltype (B) == eltype (A) != T
744+ @test @inferred (convert_eltype (eltype (B), B)) === B
745+ C = @inferred convert_eltype (T, B)
746+ @test typeof (C) <: Transpose{T}
747+ @test C == B
748+
749+ B = adjoint (A)
750+ @test eltype (B) == eltype (A) != T
751+ @test @inferred (convert_eltype (eltype (B), B)) === B
752+ C = @inferred convert_eltype (T, B)
753+ @test typeof (C) <: Adjoint{T}
754+ @test C == B
755+
756+ B = Diagonal (A)
757+ @test eltype (B) == eltype (A) != T
758+ @test @inferred (convert_eltype (eltype (B), B)) === B
759+ C = @inferred convert_eltype (T, B)
760+ @test typeof (C) <: Diagonal{T}
761+ @test C == B
762+
763+ B = Bidiagonal (A, :U )
764+ @test eltype (B) == eltype (A) != T
765+ @test @inferred (convert_eltype (eltype (B), B)) === B
766+ C = @inferred convert_eltype (T, B)
767+ @test typeof (C) <: Bidiagonal{T}
768+ @test C == B
769+
770+ B = Bidiagonal (A, :L )
771+ @test eltype (B) == eltype (A) != T
772+ @test @inferred (convert_eltype (eltype (B), B)) === B
773+ C = @inferred convert_eltype (T, B)
774+ @test typeof (C) <: Bidiagonal{T}
775+ @test C == B
776+
777+ B = Tridiagonal (A)
778+ @test eltype (B) == eltype (A) != T
779+ @test @inferred (convert_eltype (eltype (B), B)) === B
780+ C = @inferred convert_eltype (T, B)
781+ @test typeof (C) <: Tridiagonal{T}
782+ @test C == B
783+
784+ B = Hermitian (A)
785+ @test eltype (B) == eltype (A) != T
786+ @test @inferred (convert_eltype (eltype (B), B)) === B
787+ C = @inferred convert_eltype (T, B)
788+ @test typeof (C) <: Hermitian{T}
789+ @test C == B
790+
791+ B = Symmetric (A)
792+ @test eltype (B) == eltype (A) != T
793+ @test @inferred (convert_eltype (eltype (B), B)) === B
794+ C = @inferred convert_eltype (T, B)
795+ @test typeof (C) <: Symmetric{T}
796+ @test C == B
797+
798+ B = cholesky (AAt)
799+ @test eltype (B) == eltype (A) != T
800+ @test @inferred (convert_eltype (eltype (B), B)) === B
801+ C = @inferred convert_eltype (T, B)
802+ @test typeof (C) <: Cholesky{T}
803+ @test C. factors == B. factors
804+
805+ pivot = VERSION < v " 1.8.0-beta1" ? Val (true ) : RowMaximum ()
806+ B = cholesky (AAt, pivot)
807+ @test eltype (B) == eltype (A) != T
808+ @test @inferred (convert_eltype (eltype (B), B)) === B
809+ C = @inferred convert_eltype (T, B)
810+ @test typeof (C) <: CholeskyPivoted{T}
811+ @test C. factors == B. factors
812+
813+ B = svd (A)
814+ @test eltype (B) == eltype (A) != T
815+ @test @inferred (convert_eltype (eltype (B), B)) === B
816+ C = @inferred convert_eltype (T, B)
817+ @test typeof (C) <: SVD{T}
818+ @test C. U == B. U
819+ @test C. S == B. S
820+ @test C. Vt == B. Vt
821+
822+ B = qr (A)
823+ @test eltype (B) == eltype (A) != T
824+ @test @inferred (convert_eltype (eltype (B), B)) === B
825+ C = @inferred convert_eltype (T, B)
826+ @test typeof (C) <: Factorization{T}
827+ @test C. Q == B. Q
828+ @test C. R == B. R
829+
830+ pivot = isdefined (LinearAlgebra, :PivotingStrategy ) ? ColumnNorm () : Val (true )
831+ B = qr (A, pivot)
832+ @test eltype (B) == eltype (A) != T
833+ @test @inferred (convert_eltype (eltype (B), B)) === B
834+ C = @inferred convert_eltype (T, B)
835+ @test typeof (C) <: QRPivoted{T}
836+ @test C. P == B. P
837+ @test C. Q == B. Q
838+ @test C. R == B. R
839+ @test C. p == B. p
840+
841+ pivot = isdefined (LinearAlgebra, :PivotingStrategy ) ? NoPivot () : Val (false )
842+ B = lu (A, pivot)
843+ @test eltype (B) == eltype (A) != T
844+ @test @inferred (convert_eltype (eltype (B), B)) === B
845+ C = @inferred convert_eltype (T, B)
846+ @test typeof (C) <: LU{T}
847+ @test C. L == B. L
848+ @test C. U == B. U
849+ @test C. P == B. P
850+ @test C. p == B. p
851+
852+ pivot = isdefined (LinearAlgebra, :PivotingStrategy ) ? RowMaximum () : Val (true )
853+ B = lu (A, pivot)
854+ @test eltype (B) == eltype (A) != T
855+ @test @inferred (convert_eltype (eltype (B), B)) === B
856+ C = @inferred convert_eltype (T, B)
857+ @test typeof (C) <: LU{T}
858+ @test C. L == B. L
859+ @test C. U == B. U
860+ @test C. P == B. P
861+ @test C. p == B. p
862+ end
863+
735864 @testset " Unitful quantities" begin
736865 # bare_type for values
737866 @test Float64 === @inferred bare_type (u " 2.0m/s" )
0 commit comments