From e2833cedf1787fc368aaa39613d0f99cea68e441 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Fri, 24 Sep 2021 10:20:05 -0400 Subject: [PATCH 1/2] tests for converting QR eltype --- stdlib/LinearAlgebra/test/qr.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stdlib/LinearAlgebra/test/qr.jl b/stdlib/LinearAlgebra/test/qr.jl index d6085565e3c7f..2d63d03dce576 100644 --- a/stdlib/LinearAlgebra/test/qr.jl +++ b/stdlib/LinearAlgebra/test/qr.jl @@ -415,4 +415,15 @@ end @test A.Q' * B ≈ A.Q end +@testset "convert between eltypes" begin + a = rand(Float64, 10, 5) + qra = qr(a) + @test Array(LinearAlgebra.QRCompactWY{Float32}(qra.factors, qra.T)) ≈ Array(qr(Float32.(a))) + qra = qr(a, ColumnNorm()) + @test Array(QRPivoted{Float32}(qra.factors, qra.τ, qra.jpvt)) ≈ Array(qr(Float32.(a), ColumnNorm())) + a = rand(Float16, 10, 5) + qra = qr(a) + @test Array(QR{ComplexF16}(qra.factors, qra.τ)) ≈ Array(qr(ComplexF16.(a))) +end + end # module TestQR From 46ad9c9a71879e814908323e1b11f37358304587 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Mon, 27 Sep 2021 15:13:57 -0400 Subject: [PATCH 2/2] Add more tests for eltype --- stdlib/LinearAlgebra/test/qr.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/LinearAlgebra/test/qr.jl b/stdlib/LinearAlgebra/test/qr.jl index 2d63d03dce576..9706801255c76 100644 --- a/stdlib/LinearAlgebra/test/qr.jl +++ b/stdlib/LinearAlgebra/test/qr.jl @@ -418,12 +418,18 @@ end @testset "convert between eltypes" begin a = rand(Float64, 10, 5) qra = qr(a) - @test Array(LinearAlgebra.QRCompactWY{Float32}(qra.factors, qra.T)) ≈ Array(qr(Float32.(a))) + qrwy = LinearAlgebra.QRCompactWY{Float32}(qra.factors, qra.T) + @test Array(qrwy) ≈ Array(qr(Float32.(a))) + @test eltype(qrwy.factors) == eltype(qrwy.T) == Float32 qra = qr(a, ColumnNorm()) - @test Array(QRPivoted{Float32}(qra.factors, qra.τ, qra.jpvt)) ≈ Array(qr(Float32.(a), ColumnNorm())) + qrp = QRPivoted{Float32}(qra.factors, qra.τ, qra.jpvt) + @test Array(qrp) ≈ Array(qr(Float32.(a), ColumnNorm())) + @test eltype(qrp.factors) == eltype(qrp.τ) == Float32 a = rand(Float16, 10, 5) qra = qr(a) - @test Array(QR{ComplexF16}(qra.factors, qra.τ)) ≈ Array(qr(ComplexF16.(a))) + qrnonblas = QR{ComplexF16}(qra.factors, qra.τ) + @test Array(qrnonblas) ≈ Array(qr(ComplexF16.(a))) + @test eltype(qrnonblas.factors) == eltype(qrnonblas.τ) == ComplexF16 end end # module TestQR