From 4f4e2e88a0721363afcc21500b88f07a0d6bc50e Mon Sep 17 00:00:00 2001 From: leburgel Date: Wed, 4 Feb 2026 16:36:14 +0100 Subject: [PATCH 1/2] Systematically set `positive = true` --- ...MatrixAlgebraKitGenericLinearAlgebraExt.jl | 4 ++-- src/implementations/lq.jl | 8 ++++---- src/implementations/qr.jl | 12 +++++------ src/interface/decompositions.jl | 20 +++++++++---------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ext/MatrixAlgebraKitGenericLinearAlgebraExt.jl b/ext/MatrixAlgebraKitGenericLinearAlgebraExt.jl index b78b38a0..fd4cec35 100644 --- a/ext/MatrixAlgebraKitGenericLinearAlgebraExt.jl +++ b/ext/MatrixAlgebraKitGenericLinearAlgebraExt.jl @@ -78,7 +78,7 @@ function MatrixAlgebraKit.qr_null!(A::AbstractMatrix, N, alg::GLA_HouseholderQR) return _gla_householder_qr_null!(A, N; alg.kwargs...) end -function _gla_householder_qr!(A::AbstractMatrix, Q, R; positive = false, blocksize = 1, pivoted = false) +function _gla_householder_qr!(A::AbstractMatrix, Q, R; positive = true, blocksize = 1, pivoted = false) pivoted && throw(ArgumentError("Only pivoted = false implemented for GLA_HouseholderQR.")) (blocksize == 1) || throw(ArgumentError("Only blocksize = 1 implemented for GLA_HouseholderQR.")) @@ -117,7 +117,7 @@ end function _gla_householder_qr_null!( A::AbstractMatrix, N::AbstractMatrix; - positive = false, blocksize = 1, pivoted = false + positive = true, blocksize = 1, pivoted = false ) pivoted && throw(ArgumentError("Only pivoted = false implemented for GLA_HouseholderQR.")) (blocksize == 1) || throw(ArgumentError("Only blocksize = 1 implemented for GLA_HouseholderQR.")) diff --git a/src/implementations/lq.jl b/src/implementations/lq.jl index 8cff528c..b11533a8 100644 --- a/src/implementations/lq.jl +++ b/src/implementations/lq.jl @@ -145,7 +145,7 @@ end # ------------ function _lapack_lq!( A::AbstractMatrix, L::AbstractMatrix, Q::AbstractMatrix; - positive = false, pivoted = false, + positive = true, pivoted = false, blocksize = ((pivoted || A === Q) ? 1 : YALAPACK.default_qr_blocksize(A)) ) m, n = size(A) @@ -203,7 +203,7 @@ end function _lapack_lq_null!( A::AbstractMatrix, Ná´´::AbstractMatrix; - positive = false, pivoted = false, blocksize = YALAPACK.default_qr_blocksize(A) + positive = true, pivoted = false, blocksize = YALAPACK.default_qr_blocksize(A) ) m, n = size(A) minmn = min(m, n) @@ -253,7 +253,7 @@ end # Diagonal logic # -------------- function _diagonal_lq!( - A::AbstractMatrix, L::AbstractMatrix, Q::AbstractMatrix; positive::Bool = false + A::AbstractMatrix, L::AbstractMatrix, Q::AbstractMatrix; positive::Bool = true ) # note: Ad and Qd might share memory here so order of operations is important Ad = diagview(A) @@ -269,7 +269,7 @@ function _diagonal_lq!( return L, Q end -_diagonal_lq_null!(A::AbstractMatrix, N; positive::Bool = false) = N +_diagonal_lq_null!(A::AbstractMatrix, N; positive::Bool = true) = N # Native logic # ------------- diff --git a/src/implementations/qr.jl b/src/implementations/qr.jl index ffd84482..fd7ce01b 100644 --- a/src/implementations/qr.jl +++ b/src/implementations/qr.jl @@ -129,7 +129,7 @@ end # ------------ function _lapack_qr!( A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix; - positive = false, pivoted = false, + positive = true, pivoted = false, blocksize = ((pivoted || A === Q) ? 1 : YALAPACK.default_qr_blocksize(A)) ) m, n = size(A) @@ -195,7 +195,7 @@ end function _lapack_qr_null!( A::AbstractMatrix, N::AbstractMatrix; - positive = false, pivoted = false, blocksize = YALAPACK.default_qr_blocksize(A) + positive = true, pivoted = false, blocksize = YALAPACK.default_qr_blocksize(A) ) m, n = size(A) minmn = min(m, n) @@ -215,7 +215,7 @@ end # Diagonal logic # -------------- function _diagonal_qr!( - A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix; positive::Bool = false + A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix; positive::Bool = true ) # note: Ad and Qd might share memory here so order of operations is important Ad = diagview(A) @@ -231,7 +231,7 @@ function _diagonal_qr!( return Q, R end -_diagonal_qr_null!(A::AbstractMatrix, N; positive::Bool = false) = N +_diagonal_qr_null!(A::AbstractMatrix, N; positive::Bool = true) = N # GPU logic # -------------- @@ -269,7 +269,7 @@ function _gpu_unmqr!( end function _gpu_qr!( - A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix; positive = false, blocksize = 1, pivoted = false + A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix; positive = true, blocksize = 1, pivoted = false ) blocksize > 1 && throw(ArgumentError("CUSOLVER/ROCSOLVER does not provide a blocked implementation for a QR decomposition")) @@ -310,7 +310,7 @@ function _gpu_qr!( end function _gpu_qr_null!( - A::AbstractMatrix, N::AbstractMatrix; positive = false, blocksize = 1, pivoted = false + A::AbstractMatrix, N::AbstractMatrix; positive = true, blocksize = 1, pivoted = false ) blocksize > 1 && throw(ArgumentError("CUSOLVER/ROCSOLVER does not provide a blocked implementation for a QR decomposition")) diff --git a/src/interface/decompositions.jl b/src/interface/decompositions.jl index 3a623b87..19f20e8e 100644 --- a/src/interface/decompositions.jl +++ b/src/interface/decompositions.jl @@ -28,34 +28,34 @@ by construction. @algdef Native_HouseholderLQ """ - LAPACK_HouseholderQR(; blocksize, positive = false, pivoted = false) + LAPACK_HouseholderQR(; blocksize, positive = true, pivoted = false) Algorithm type to denote the standard LAPACK algorithm for computing the QR decomposition of a matrix using Householder reflectors. The specific LAPACK function can be controlled using the keyword arugments, i.e. `?geqrt` will be chosen if `blocksize > 1`. With `blocksize == 1`, `?geqrf` will be chosen if `pivoted == false` and `?geqp3` will be chosen -if `pivoted == true`. The keyword `positive = true` can be used to ensure that the diagonal +if `pivoted == true`. The keyword `positive = true` is used to ensure that the diagonal elements of `R` are non-negative. """ @algdef LAPACK_HouseholderQR """ - LAPACK_HouseholderLQ(; blocksize, positive = false) + LAPACK_HouseholderLQ(; blocksize, positive = true) Algorithm type to denote the standard LAPACK algorithm for computing the LQ decomposition of a matrix using Householder reflectors. The specific LAPACK function can be controlled using the keyword arugments, i.e. `?gelqt` will be chosen if `blocksize > 1` or `?gelqf` will be -chosen if `blocksize == 1`. The keyword `positive = true` can be used to ensure that the diagonal -elements of `L` are non-negative. +chosen if `blocksize == 1`. The keyword `positive = true` is used to ensure that the +diagonal elements of `L` are non-negative. """ @algdef LAPACK_HouseholderLQ """ - GLA_HouseholderQR(; positive = false) + GLA_HouseholderQR(; positive = true) Algorithm type to denote the GenericLinearAlgebra.jl implementation for computing the QR decomposition of a matrix using Householder reflectors. Currently, only `blocksize = 1` and `pivoted == false` -are supported. The keyword `positive = true` can be used to ensure that the diagonal elements +are supported. The keyword `positive = true` is used to ensure that the diagonal elements of `R` are non-negative. """ @algdef GLA_HouseholderQR @@ -230,7 +230,7 @@ end # CUSOLVER ALGORITHMS # ========================= """ - CUSOLVER_HouseholderQR(; positive = false) + CUSOLVER_HouseholderQR(; positive = true) Algorithm type to denote the standard CUSOLVER algorithm for computing the QR decomposition of a matrix using Householder reflectors. The keyword `positive = true` can be used to ensure that @@ -318,10 +318,10 @@ const CUSOLVER_SVDAlgorithm = Union{ # ROCSOLVER ALGORITHMS # ========================= """ - ROCSOLVER_HouseholderQR(; positive = false) + ROCSOLVER_HouseholderQR(; positive = true) Algorithm type to denote the standard ROCSOLVER algorithm for computing the QR decomposition of -a matrix using Householder reflectors. The keyword `positive=true` can be used to ensure that +a matrix using Householder reflectors. The keyword `positive = true` is used to ensure that the diagonal elements of `R` are non-negative. """ @algdef ROCSOLVER_HouseholderQR From 4643634fcd4ee0fce8b7afe5a0a8501a16a10329 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Wed, 4 Feb 2026 13:49:45 -0500 Subject: [PATCH 2/2] update changelog --- docs/src/changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/changelog.md b/docs/src/changelog.md index ec5637b1..9147c4da 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -30,6 +30,8 @@ When releasing a new version, move the "Unreleased" changes to a new version sec ### Fixed +- QR and LQ decompositions were supposed to default to `positive = true` ([#170](https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/pull/170)). + ## [0.6.4](https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/compare/v0.6.3...v0.6.4) - 2026-01-29 ### Added