Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ext/MatrixAlgebraKitGenericLinearAlgebraExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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."))

Expand Down Expand Up @@ -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."))
Expand Down
8 changes: 4 additions & 4 deletions src/implementations/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
# -------------
Expand Down
12 changes: 6 additions & 6 deletions src/implementations/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
# --------------
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))
Expand Down
20 changes: 10 additions & 10 deletions src/interface/decompositions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down