From 8559e47338248bdc73bbfc72d31d8569cc431d23 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Fri, 28 May 2021 18:07:45 +0200 Subject: [PATCH] Replace Val-types by singleton types in `lu` and `qr` (#40623) Co-authored-by: Andreas Noack --- NEWS.md | 4 ++ stdlib/LinearAlgebra/src/LinearAlgebra.jl | 7 +++ stdlib/LinearAlgebra/src/dense.jl | 2 +- stdlib/LinearAlgebra/src/factorization.jl | 6 +-- stdlib/LinearAlgebra/src/generic.jl | 2 +- stdlib/LinearAlgebra/src/lu.jl | 52 +++++++++++++-------- stdlib/LinearAlgebra/src/qr.jl | 29 +++++++----- stdlib/LinearAlgebra/test/diagonal.jl | 2 +- stdlib/LinearAlgebra/test/generic.jl | 4 +- stdlib/LinearAlgebra/test/lq.jl | 2 +- stdlib/LinearAlgebra/test/lu.jl | 24 +++++----- stdlib/LinearAlgebra/test/qr.jl | 22 ++++----- stdlib/LinearAlgebra/test/special.jl | 4 +- stdlib/LinearAlgebra/test/uniformscaling.jl | 2 +- 14 files changed, 95 insertions(+), 67 deletions(-) diff --git a/NEWS.md b/NEWS.md index bf9b0ceb6b61c3..fcd5168dd9514e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -115,6 +115,10 @@ Standard library changes * The shape of an `UpperHessenberg` matrix is preserved under certain arithmetic operations, e.g. when multiplying or dividing by an `UpperTriangular` matrix. ([#40039]) * `cis(A)` now supports matrix arguments ([#40194]). * `dot` now supports `UniformScaling` with `AbstractMatrix` ([#40250]). +* `qr[!]` and `lu[!]` now support `LinearAlgebra.PivotingStrategy` (singleton type) values + as their optional `pivot` argument: defaults are `qr(A, NoPivot())` (vs. + `qr(A, ColumnNorm())` for pivoting) and `lu(A, RowMaximum())` (vs. `lu(A, NoPivot())` + without pivoting); the former `Val{true/false}`-based calls are deprecated. ([#40623]) * `det(M::AbstractMatrix{BigInt})` now calls `det_bareiss(M)`, which uses the [Bareiss](https://en.wikipedia.org/wiki/Bareiss_algorithm) algorithm to calculate precise values.([#40868]). #### Markdown diff --git a/stdlib/LinearAlgebra/src/LinearAlgebra.jl b/stdlib/LinearAlgebra/src/LinearAlgebra.jl index 855e49265af2db..d5a2a64467f932 100644 --- a/stdlib/LinearAlgebra/src/LinearAlgebra.jl +++ b/stdlib/LinearAlgebra/src/LinearAlgebra.jl @@ -35,6 +35,7 @@ export BunchKaufman, Cholesky, CholeskyPivoted, + ColumnNorm, Eigen, GeneralizedEigen, GeneralizedSVD, @@ -42,12 +43,14 @@ export Hessenberg, LU, LDLt, + NoPivot, QR, QRPivoted, LQ, Schur, SVD, Hermitian, + RowMaximum, Symmetric, LowerTriangular, UpperTriangular, @@ -164,6 +167,10 @@ abstract type Algorithm end struct DivideAndConquer <: Algorithm end struct QRIteration <: Algorithm end +abstract type PivotingStrategy end +struct NoPivot <: PivotingStrategy end +struct RowMaximum <: PivotingStrategy end +struct ColumnNorm <: PivotingStrategy end # Check that stride of matrix/vector is 1 # Writing like this to avoid splatting penalty when called with multiple arguments, diff --git a/stdlib/LinearAlgebra/src/dense.jl b/stdlib/LinearAlgebra/src/dense.jl index ff789a9fd11b22..4159525d07679e 100644 --- a/stdlib/LinearAlgebra/src/dense.jl +++ b/stdlib/LinearAlgebra/src/dense.jl @@ -1371,7 +1371,7 @@ function factorize(A::StridedMatrix{T}) where T end return lu(A) end - qr(A, Val(true)) + qr(A, ColumnNorm()) end factorize(A::Adjoint) = adjoint(factorize(parent(A))) factorize(A::Transpose) = transpose(factorize(parent(A))) diff --git a/stdlib/LinearAlgebra/src/factorization.jl b/stdlib/LinearAlgebra/src/factorization.jl index 3e335ed391ad69..5ff215a3eb6651 100644 --- a/stdlib/LinearAlgebra/src/factorization.jl +++ b/stdlib/LinearAlgebra/src/factorization.jl @@ -16,9 +16,9 @@ size(F::Adjoint{<:Any,<:Factorization}) = reverse(size(parent(F))) size(F::Transpose{<:Any,<:Factorization}) = reverse(size(parent(F))) checkpositivedefinite(info) = info == 0 || throw(PosDefException(info)) -checknonsingular(info, pivoted::Val{true}) = info == 0 || throw(SingularException(info)) -checknonsingular(info, pivoted::Val{false}) = info == 0 || throw(ZeroPivotException(info)) -checknonsingular(info) = checknonsingular(info, Val{true}()) +checknonsingular(info, ::RowMaximum) = info == 0 || throw(SingularException(info)) +checknonsingular(info, ::NoPivot) = info == 0 || throw(ZeroPivotException(info)) +checknonsingular(info) = checknonsingular(info, RowMaximum()) """ issuccess(F::Factorization) diff --git a/stdlib/LinearAlgebra/src/generic.jl b/stdlib/LinearAlgebra/src/generic.jl index e0e7cebe2b0e1c..c9c624500e9281 100644 --- a/stdlib/LinearAlgebra/src/generic.jl +++ b/stdlib/LinearAlgebra/src/generic.jl @@ -1141,7 +1141,7 @@ function (\)(A::AbstractMatrix, B::AbstractVecOrMat) end return lu(A) \ B end - return qr(A,Val(true)) \ B + return qr(A, ColumnNorm()) \ B end (\)(a::AbstractVector, b::AbstractArray) = pinv(a) * b diff --git a/stdlib/LinearAlgebra/src/lu.jl b/stdlib/LinearAlgebra/src/lu.jl index 2d915680d5381d..e55508db6b397a 100644 --- a/stdlib/LinearAlgebra/src/lu.jl +++ b/stdlib/LinearAlgebra/src/lu.jl @@ -76,22 +76,26 @@ adjoint(F::LU) = Adjoint(F) transpose(F::LU) = Transpose(F) # StridedMatrix -function lu!(A::StridedMatrix{T}, pivot::Union{Val{false}, Val{true}} = Val(true); - check::Bool = true) where T<:BlasFloat - if pivot === Val(false) - return generic_lufact!(A, pivot; check = check) - end +lu!(A::StridedMatrix{<:BlasFloat}; check::Bool = true) = lu!(A, RowMaximum(); check=check) +function lu!(A::StridedMatrix{T}, ::RowMaximum; check::Bool = true) where {T<:BlasFloat} lpt = LAPACK.getrf!(A) check && checknonsingular(lpt[3]) return LU{T,typeof(A)}(lpt[1], lpt[2], lpt[3]) end -function lu!(A::HermOrSym, pivot::Union{Val{false}, Val{true}} = Val(true); check::Bool = true) +function lu!(A::StridedMatrix{<:BlasFloat}, pivot::NoPivot; check::Bool = true) + return generic_lufact!(A, pivot; check = check) +end +function lu!(A::HermOrSym, pivot::Union{RowMaximum,NoPivot} = RowMaximum(); check::Bool = true) copytri!(A.data, A.uplo, isa(A, Hermitian)) lu!(A.data, pivot; check = check) end +# for backward compatibility +# TODO: remove towards Julia v2 +@deprecate lu!(A::Union{StridedMatrix,HermOrSym,Tridiagonal}, ::Val{true}; check::Bool = true) lu!(A, RowMaximum(); check=check) +@deprecate lu!(A::Union{StridedMatrix,HermOrSym,Tridiagonal}, ::Val{false}; check::Bool = true) lu!(A, NoPivot(); check=check) """ - lu!(A, pivot=Val(true); check = true) -> LU + lu!(A, pivot = RowMaximum(); check = true) -> LU `lu!` is the same as [`lu`](@ref), but saves space by overwriting the input `A`, instead of creating a copy. An [`InexactError`](@ref) @@ -127,19 +131,22 @@ Stacktrace: [...] ``` """ -lu!(A::StridedMatrix, pivot::Union{Val{false}, Val{true}} = Val(true); check::Bool = true) = +lu!(A::StridedMatrix, pivot::Union{RowMaximum,NoPivot} = RowMaximum(); check::Bool = true) = generic_lufact!(A, pivot; check = check) -function generic_lufact!(A::StridedMatrix{T}, ::Val{Pivot} = Val(true); - check::Bool = true) where {T,Pivot} +function generic_lufact!(A::StridedMatrix{T}, pivot::Union{RowMaximum,NoPivot} = RowMaximum(); + check::Bool = true) where {T} + # Extract values m, n = size(A) minmn = min(m,n) + + # Initialize variables info = 0 ipiv = Vector{BlasInt}(undef, minmn) @inbounds begin for k = 1:minmn # find index max kp = k - if Pivot && k < m + if pivot === RowMaximum() && k < m amax = abs(A[k, k]) for i = k+1:m absi = abs(A[i,k]) @@ -175,7 +182,7 @@ function generic_lufact!(A::StridedMatrix{T}, ::Val{Pivot} = Val(true); end end end - check && checknonsingular(info, Val{Pivot}()) + check && checknonsingular(info, pivot) return LU{T,typeof(A)}(A, ipiv, convert(BlasInt, info)) end @@ -200,7 +207,7 @@ end # for all other types we must promote to a type which is stable under division """ - lu(A, pivot=Val(true); check = true) -> F::LU + lu(A, pivot = RowMaximum(); check = true) -> F::LU Compute the LU factorization of `A`. @@ -211,7 +218,7 @@ validity (via [`issuccess`](@ref)) lies with the user. In most cases, if `A` is a subtype `S` of `AbstractMatrix{T}` with an element type `T` supporting `+`, `-`, `*` and `/`, the return type is `LU{T,S{T}}`. If pivoting is chosen (default) the element type should also support [`abs`](@ref) and -[`<`](@ref). +[`<`](@ref). Pivoting can be turned off by passing `pivot = NoPivot()`. The individual components of the factorization `F` can be accessed via [`getproperty`](@ref): @@ -267,11 +274,14 @@ julia> l == F.L && u == F.U && p == F.p true ``` """ -function lu(A::AbstractMatrix{T}, pivot::Union{Val{false}, Val{true}}=Val(true); - check::Bool = true) where T +function lu(A::AbstractMatrix{T}, pivot::Union{RowMaximum,NoPivot} = RowMaximum(); check::Bool = true) where {T} S = lutype(T) lu!(copy_oftype(A, S), pivot; check = check) end +# TODO: remove for Julia v2.0 +@deprecate lu(A::AbstractMatrix, ::Val{true}; check::Bool = true) lu(A, RowMaximum(); check=check) +@deprecate lu(A::AbstractMatrix, ::Val{false}; check::Bool = true) lu(A, NoPivot(); check=check) + lu(S::LU) = S function lu(x::Number; check::Bool=true) @@ -481,9 +491,11 @@ inv(A::LU{<:BlasFloat,<:StridedMatrix}) = inv!(copy(A)) # Tridiagonal # See dgttrf.f -function lu!(A::Tridiagonal{T,V}, pivot::Union{Val{false}, Val{true}} = Val(true); - check::Bool = true) where {T,V} +function lu!(A::Tridiagonal{T,V}, pivot::Union{RowMaximum,NoPivot} = RowMaximum(); check::Bool = true) where {T,V} + # Extract values n = size(A, 1) + + # Initialize variables info = 0 ipiv = Vector{BlasInt}(undef, n) dl = A.dl @@ -500,7 +512,7 @@ function lu!(A::Tridiagonal{T,V}, pivot::Union{Val{false}, Val{true}} = Val(true end for i = 1:n-2 # pivot or not? - if pivot === Val(false) || abs(d[i]) >= abs(dl[i]) + if pivot === NoPivot() || abs(d[i]) >= abs(dl[i]) # No interchange if d[i] != 0 fact = dl[i]/d[i] @@ -523,7 +535,7 @@ function lu!(A::Tridiagonal{T,V}, pivot::Union{Val{false}, Val{true}} = Val(true end if n > 1 i = n-1 - if pivot === Val(false) || abs(d[i]) >= abs(dl[i]) + if pivot === NoPivot() || abs(d[i]) >= abs(dl[i]) if d[i] != 0 fact = dl[i]/d[i] dl[i] = fact diff --git a/stdlib/LinearAlgebra/src/qr.jl b/stdlib/LinearAlgebra/src/qr.jl index cd5d17565fa3f6..390c8a58757735 100644 --- a/stdlib/LinearAlgebra/src/qr.jl +++ b/stdlib/LinearAlgebra/src/qr.jl @@ -246,17 +246,17 @@ function qrfactPivotedUnblocked!(A::AbstractMatrix) end # LAPACK version -qr!(A::StridedMatrix{<:BlasFloat}, ::Val{false} = Val(false); blocksize=36) = +qr!(A::StridedMatrix{<:BlasFloat}, ::NoPivot; blocksize=36) = QRCompactWY(LAPACK.geqrt!(A, min(min(size(A)...), blocksize))...) -qr!(A::StridedMatrix{<:BlasFloat}, ::Val{true}) = QRPivoted(LAPACK.geqp3!(A)...) +qr!(A::StridedMatrix{<:BlasFloat}, ::ColumnNorm) = QRPivoted(LAPACK.geqp3!(A)...) # Generic fallbacks """ - qr!(A, pivot=Val(false); blocksize) + qr!(A, pivot = NoPivot(); blocksize) -`qr!` is the same as [`qr`](@ref) when `A` is a subtype of -[`StridedMatrix`](@ref), but saves space by overwriting the input `A`, instead of creating a copy. +`qr!` is the same as [`qr`](@ref) when `A` is a subtype of [`StridedMatrix`](@ref), +but saves space by overwriting the input `A`, instead of creating a copy. An [`InexactError`](@ref) exception is thrown if the factorization produces a number not representable by the element type of `A`, e.g. for integer types. @@ -292,14 +292,17 @@ Stacktrace: [...] ``` """ -qr!(A::AbstractMatrix, ::Val{false}) = qrfactUnblocked!(A) -qr!(A::AbstractMatrix, ::Val{true}) = qrfactPivotedUnblocked!(A) -qr!(A::AbstractMatrix) = qr!(A, Val(false)) +qr!(A::AbstractMatrix, ::NoPivot) = qrfactUnblocked!(A) +qr!(A::AbstractMatrix, ::ColumnNorm) = qrfactPivotedUnblocked!(A) +qr!(A::AbstractMatrix) = qr!(A, NoPivot()) +# TODO: Remove in Julia v2.0 +@deprecate qr!(A::AbstractMatrix, ::Val{true}) qr!(A, ColumnNorm()) +@deprecate qr!(A::AbstractMatrix, ::Val{false}) qr!(A, NoPivot()) _qreltype(::Type{T}) where T = typeof(zero(T)/sqrt(abs2(one(T)))) """ - qr(A, pivot=Val(false); blocksize) -> F + qr(A, pivot = NoPivot(); blocksize) -> F Compute the QR factorization of the matrix `A`: an orthogonal (or unitary if `A` is complex-valued) matrix `Q`, and an upper triangular matrix `R` such that @@ -310,7 +313,7 @@ A = Q R The returned object `F` stores the factorization in a packed format: - - if `pivot == Val(true)` then `F` is a [`QRPivoted`](@ref) object, + - if `pivot == ColumnNorm()` then `F` is a [`QRPivoted`](@ref) object, - otherwise if the element type of `A` is a BLAS type ([`Float32`](@ref), [`Float64`](@ref), `ComplexF32` or `ComplexF64`), then `F` is a [`QRCompactWY`](@ref) object, @@ -340,7 +343,7 @@ and `F.Q*A` are supported. A `Q` matrix can be converted into a regular matrix w orthogonal matrix. The block size for QR decomposition can be specified by keyword argument -`blocksize :: Integer` when `pivot == Val(false)` and `A isa StridedMatrix{<:BlasFloat}`. +`blocksize :: Integer` when `pivot == NoPivot()` and `A isa StridedMatrix{<:BlasFloat}`. It is ignored when `blocksize > minimum(size(A))`. See [`QRCompactWY`](@ref). !!! compat "Julia 1.4" @@ -382,6 +385,10 @@ function qr(A::AbstractMatrix{T}, arg...; kwargs...) where T copyto!(AA, A) return qr!(AA, arg...; kwargs...) end +# TODO: remove in Julia v2.0 +@deprecate qr(A::AbstractMatrix, ::Val{false}; kwargs...) qr(A, NoPivot(); kwargs...) +@deprecate qr(A::AbstractMatrix, ::Val{true}; kwargs...) qr(A, ColumnNorm(); kwargs...) + qr(x::Number) = qr(fill(x,1,1)) function qr(v::AbstractVector) require_one_based_indexing(v) diff --git a/stdlib/LinearAlgebra/test/diagonal.jl b/stdlib/LinearAlgebra/test/diagonal.jl index b6b52c0a0770c5..dcd82618c4968d 100644 --- a/stdlib/LinearAlgebra/test/diagonal.jl +++ b/stdlib/LinearAlgebra/test/diagonal.jl @@ -565,7 +565,7 @@ end D = Diagonal(randn(5)) Q = qr(randn(5, 5)).Q @test D * Q' == Array(D) * Q' - Q = qr(randn(5, 5), Val(true)).Q + Q = qr(randn(5, 5), ColumnNorm()).Q @test_throws ArgumentError lmul!(Q, D) end diff --git a/stdlib/LinearAlgebra/test/generic.jl b/stdlib/LinearAlgebra/test/generic.jl index cde16288f8f671..489b96be56019a 100644 --- a/stdlib/LinearAlgebra/test/generic.jl +++ b/stdlib/LinearAlgebra/test/generic.jl @@ -387,13 +387,13 @@ LinearAlgebra.Transpose(a::ModInt{n}) where {n} = transpose(a) A = [ModInt{2}(1) ModInt{2}(0); ModInt{2}(1) ModInt{2}(1)] b = [ModInt{2}(1), ModInt{2}(0)] - @test A*(lu(A, Val(false))\b) == b + @test A*(lu(A, NoPivot())\b) == b # Needed for pivoting: Base.abs(a::ModInt{n}) where {n} = a Base.:<(a::ModInt{n}, b::ModInt{n}) where {n} = a.k < b.k - @test A*(lu(A, Val(true))\b) == b + @test A*(lu(A, RowMaximum())\b) == b end @testset "Issue 18742" begin diff --git a/stdlib/LinearAlgebra/test/lq.jl b/stdlib/LinearAlgebra/test/lq.jl index 883793c55d4dd2..8915324af94614 100644 --- a/stdlib/LinearAlgebra/test/lq.jl +++ b/stdlib/LinearAlgebra/test/lq.jl @@ -40,7 +40,7 @@ rectangularQ(Q::LinearAlgebra.LQPackedQ) = convert(Array, Q) lqa = lq(a) x = lqa\b l,q = lqa.L, lqa.Q - qra = qr(a, Val(true)) + qra = qr(a, ColumnNorm()) @testset "Basic ops" begin @test size(lqa,1) == size(a,1) @test size(lqa,3) == 1 diff --git a/stdlib/LinearAlgebra/test/lu.jl b/stdlib/LinearAlgebra/test/lu.jl index 8e6c06cdbd12e5..6a1c34e511c2ee 100644 --- a/stdlib/LinearAlgebra/test/lu.jl +++ b/stdlib/LinearAlgebra/test/lu.jl @@ -61,7 +61,7 @@ dimg = randn(n)/2 lua = factorize(a) @test_throws ErrorException lua.Z l,u,p = lua.L, lua.U, lua.p - ll,ul,pl = lu(a) + ll,ul,pl = @inferred lu(a) @test ll * ul ≈ a[pl,:] @test l*u ≈ a[p,:] @test (l*u)[invperm(p),:] ≈ a @@ -85,9 +85,9 @@ dimg = randn(n)/2 end κd = cond(Array(d),1) @testset "Tridiagonal LU" begin - lud = lu(d) + lud = @inferred lu(d) @test LinearAlgebra.issuccess(lud) - @test lu(lud) == lud + @test @inferred(lu(lud)) == lud @test_throws ErrorException lud.Z @test lud.L*lud.U ≈ lud.P*Array(d) @test lud.L*lud.U ≈ Array(d)[lud.p,:] @@ -199,14 +199,14 @@ dimg = randn(n)/2 @test lua.L*lua.U ≈ lua.P*a[:,1:n1] end @testset "Fat LU" begin - lua = lu(a[1:n1,:]) + lua = @inferred lu(a[1:n1,:]) @test lua.L*lua.U ≈ lua.P*a[1:n1,:] end end @testset "LU of Symmetric/Hermitian" begin for HS in (Hermitian(a'a), Symmetric(a'a)) - luhs = lu(HS) + luhs = @inferred lu(HS) @test luhs.L*luhs.U ≈ luhs.P*Matrix(HS) end end @@ -229,12 +229,12 @@ end @test_throws SingularException lu!(copy(A); check = true) @test !issuccess(lu(A; check = false)) @test !issuccess(lu!(copy(A); check = false)) - @test_throws ZeroPivotException lu(A, Val(false)) - @test_throws ZeroPivotException lu!(copy(A), Val(false)) - @test_throws ZeroPivotException lu(A, Val(false); check = true) - @test_throws ZeroPivotException lu!(copy(A), Val(false); check = true) - @test !issuccess(lu(A, Val(false); check = false)) - @test !issuccess(lu!(copy(A), Val(false); check = false)) + @test_throws ZeroPivotException lu(A, NoPivot()) + @test_throws ZeroPivotException lu!(copy(A), NoPivot()) + @test_throws ZeroPivotException lu(A, NoPivot(); check = true) + @test_throws ZeroPivotException lu!(copy(A), NoPivot(); check = true) + @test !issuccess(lu(A, NoPivot(); check = false)) + @test !issuccess(lu!(copy(A), NoPivot(); check = false)) F = lu(A; check = false) @test sprint((io, x) -> show(io, "text/plain", x), F) == "Failed factorization of type $(typeof(F))" @@ -320,7 +320,7 @@ include("trickyarithmetic.jl") @testset "lu with type whose sum is another type" begin A = TrickyArithmetic.A[1 2; 3 4] ElT = TrickyArithmetic.D{TrickyArithmetic.C,TrickyArithmetic.C} - B = lu(A, Val(false)) + B = lu(A, NoPivot()) @test B isa LinearAlgebra.LU{ElT,Matrix{ElT}} end diff --git a/stdlib/LinearAlgebra/test/qr.jl b/stdlib/LinearAlgebra/test/qr.jl index 394b371e02eac4..16f828b4f88611 100644 --- a/stdlib/LinearAlgebra/test/qr.jl +++ b/stdlib/LinearAlgebra/test/qr.jl @@ -49,7 +49,6 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = convert(Array, Q) a_1 = size(a, 1) @testset "QR decomposition (without pivoting)" begin qra = @inferred qr(a) - @inferred qr(a) q, r = qra.Q, qra.R @test_throws ErrorException qra.Z @test q'*squareQ(q) ≈ Matrix(I, a_1, a_1) @@ -78,8 +77,7 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = convert(Array, Q) @test Base.propertynames(qra) == (:R, :Q) end @testset "Thin QR decomposition (without pivoting)" begin - qra = @inferred qr(a[:, 1:n1], Val(false)) - @inferred qr(a[:, 1:n1], Val(false)) + qra = @inferred qr(a[:, 1:n1], NoPivot()) q,r = qra.Q, qra.R @test_throws ErrorException qra.Z @test q'*squareQ(q) ≈ Matrix(I, a_1, a_1) @@ -104,7 +102,7 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = convert(Array, Q) @test Base.propertynames(qra) == (:R, :Q) end @testset "(Automatic) Fat (pivoted) QR decomposition" begin - @inferred qr(a, Val(true)) + @inferred qr(a, ColumnNorm()) qrpa = factorize(a[1:n1,:]) q,r = qrpa.Q, qrpa.R @@ -190,7 +188,7 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = convert(Array, Q) @test mul!(c, b, q') ≈ b*q' @test_throws DimensionMismatch mul!(Matrix{eltya}(I, n+1, n), q, b) - qra = qr(a[:,1:n1], Val(false)) + qra = qr(a[:,1:n1], NoPivot()) q, r = qra.Q, qra.R @test rmul!(copy(squareQ(q)'), q) ≈ Matrix(I, n, n) @test_throws DimensionMismatch rmul!(Matrix{eltya}(I, n+1, n+1),q) @@ -215,8 +213,8 @@ end @testset "transpose errors" begin @test_throws MethodError transpose(qr(randn(3,3))) @test_throws MethodError adjoint(qr(randn(3,3))) - @test_throws MethodError transpose(qr(randn(3,3), Val(false))) - @test_throws MethodError adjoint(qr(randn(3,3), Val(false))) + @test_throws MethodError transpose(qr(randn(3,3), NoPivot())) + @test_throws MethodError adjoint(qr(randn(3,3), NoPivot())) @test_throws MethodError transpose(qr(big.(randn(3,3)))) @test_throws MethodError adjoint(qr(big.(randn(3,3)))) end @@ -256,7 +254,7 @@ end A = zeros(1, 2) B = zeros(1, 1) @test A \ B == zeros(2, 1) - @test qr(A, Val(true)) \ B == zeros(2, 1) + @test qr(A, ColumnNorm()) \ B == zeros(2, 1) end @testset "Issue 24107" begin @@ -278,7 +276,7 @@ end @test A \b ≈ ldiv!(c, qr(A ), b) @test b == b0 c0 = copy(c) - @test Ac\c ≈ ldiv!(b, qr(Ac, Val(true)), c) + @test Ac\c ≈ ldiv!(b, qr(Ac, ColumnNorm()), c) @test c0 == c end @@ -295,11 +293,11 @@ end @testset "det(Q::Union{QRCompactWYQ, QRPackedQ})" begin # 40 is the number larger than the default block size 36 of QRCompactWY - @testset for n in [1:3; 40], m in [1:3; 40], pivot in [false, true] + @testset for n in [1:3; 40], m in [1:3; 40], pivot in (NoPivot(), ColumnNorm()) @testset "real" begin @testset for k in 0:min(n, m, 5) A = cat(Array(I(k)), randn(n - k, m - k); dims=(1, 2)) - Q, = qr(A, Val(pivot)) + Q, = qr(A, pivot) @test det(Q) ≈ det(collect(Q)) @test abs(det(Q)) ≈ 1 end @@ -307,7 +305,7 @@ end @testset "complex" begin @testset for k in 0:min(n, m, 5) A = cat(Array(I(k)), randn(ComplexF64, n - k, m - k); dims=(1, 2)) - Q, = qr(A, Val(pivot)) + Q, = qr(A, pivot) @test det(Q) ≈ det(collect(Q)) @test abs(det(Q)) ≈ 1 end diff --git a/stdlib/LinearAlgebra/test/special.jl b/stdlib/LinearAlgebra/test/special.jl index c23371f3d072e0..48cb65e33eb746 100644 --- a/stdlib/LinearAlgebra/test/special.jl +++ b/stdlib/LinearAlgebra/test/special.jl @@ -192,10 +192,10 @@ end a = rand(n,n) atri = typ(a) b = rand(n,n) - qrb = qr(b,Val(true)) + qrb = qr(b, ColumnNorm()) @test *(atri, adjoint(qrb.Q)) ≈ Matrix(atri) * qrb.Q' @test rmul!(copy(atri), adjoint(qrb.Q)) ≈ Matrix(atri) * qrb.Q' - qrb = qr(b,Val(false)) + qrb = qr(b, NoPivot()) @test *(atri, adjoint(qrb.Q)) ≈ Matrix(atri) * qrb.Q' @test rmul!(copy(atri), adjoint(qrb.Q)) ≈ Matrix(atri) * qrb.Q' end diff --git a/stdlib/LinearAlgebra/test/uniformscaling.jl b/stdlib/LinearAlgebra/test/uniformscaling.jl index b7b2e5c81cf88d..8c69308d06ce8e 100644 --- a/stdlib/LinearAlgebra/test/uniformscaling.jl +++ b/stdlib/LinearAlgebra/test/uniformscaling.jl @@ -500,7 +500,7 @@ end @testset "Factorization solutions" begin J = complex(randn(),randn()) * I - qrp = A -> qr(A, Val(true)) + qrp = A -> qr(A, ColumnNorm()) # thin matrices X = randn(3,2)