Skip to content

Commit 6fce366

Browse files
leburgellkdvos
andauthored
Change QR/LQ decompositions to use positive = true by default (#170)
* Systematically set `positive = true` * update changelog --------- Co-authored-by: Lukas Devos <ldevos98@gmail.com>
1 parent f6a6372 commit 6fce366

5 files changed

Lines changed: 24 additions & 22 deletions

File tree

docs/src/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
3030

3131
### Fixed
3232

33+
- QR and LQ decompositions were supposed to default to `positive = true` ([#170](https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/pull/170)).
34+
3335
## [0.6.4](https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/compare/v0.6.3...v0.6.4) - 2026-01-29
3436

3537
### Added

ext/MatrixAlgebraKitGenericLinearAlgebraExt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function MatrixAlgebraKit.qr_null!(A::AbstractMatrix, N, alg::GLA_HouseholderQR)
7878
return _gla_householder_qr_null!(A, N; alg.kwargs...)
7979
end
8080

81-
function _gla_householder_qr!(A::AbstractMatrix, Q, R; positive = false, blocksize = 1, pivoted = false)
81+
function _gla_householder_qr!(A::AbstractMatrix, Q, R; positive = true, blocksize = 1, pivoted = false)
8282
pivoted && throw(ArgumentError("Only pivoted = false implemented for GLA_HouseholderQR."))
8383
(blocksize == 1) || throw(ArgumentError("Only blocksize = 1 implemented for GLA_HouseholderQR."))
8484

@@ -117,7 +117,7 @@ end
117117

118118
function _gla_householder_qr_null!(
119119
A::AbstractMatrix, N::AbstractMatrix;
120-
positive = false, blocksize = 1, pivoted = false
120+
positive = true, blocksize = 1, pivoted = false
121121
)
122122
pivoted && throw(ArgumentError("Only pivoted = false implemented for GLA_HouseholderQR."))
123123
(blocksize == 1) || throw(ArgumentError("Only blocksize = 1 implemented for GLA_HouseholderQR."))

src/implementations/lq.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ end
145145
# ------------
146146
function _lapack_lq!(
147147
A::AbstractMatrix, L::AbstractMatrix, Q::AbstractMatrix;
148-
positive = false, pivoted = false,
148+
positive = true, pivoted = false,
149149
blocksize = ((pivoted || A === Q) ? 1 : YALAPACK.default_qr_blocksize(A))
150150
)
151151
m, n = size(A)
@@ -203,7 +203,7 @@ end
203203

204204
function _lapack_lq_null!(
205205
A::AbstractMatrix, Nᴴ::AbstractMatrix;
206-
positive = false, pivoted = false, blocksize = YALAPACK.default_qr_blocksize(A)
206+
positive = true, pivoted = false, blocksize = YALAPACK.default_qr_blocksize(A)
207207
)
208208
m, n = size(A)
209209
minmn = min(m, n)
@@ -253,7 +253,7 @@ end
253253
# Diagonal logic
254254
# --------------
255255
function _diagonal_lq!(
256-
A::AbstractMatrix, L::AbstractMatrix, Q::AbstractMatrix; positive::Bool = false
256+
A::AbstractMatrix, L::AbstractMatrix, Q::AbstractMatrix; positive::Bool = true
257257
)
258258
# note: Ad and Qd might share memory here so order of operations is important
259259
Ad = diagview(A)
@@ -269,7 +269,7 @@ function _diagonal_lq!(
269269
return L, Q
270270
end
271271

272-
_diagonal_lq_null!(A::AbstractMatrix, N; positive::Bool = false) = N
272+
_diagonal_lq_null!(A::AbstractMatrix, N; positive::Bool = true) = N
273273

274274
# Native logic
275275
# -------------

src/implementations/qr.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ end
129129
# ------------
130130
function _lapack_qr!(
131131
A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix;
132-
positive = false, pivoted = false,
132+
positive = true, pivoted = false,
133133
blocksize = ((pivoted || A === Q) ? 1 : YALAPACK.default_qr_blocksize(A))
134134
)
135135
m, n = size(A)
@@ -195,7 +195,7 @@ end
195195

196196
function _lapack_qr_null!(
197197
A::AbstractMatrix, N::AbstractMatrix;
198-
positive = false, pivoted = false, blocksize = YALAPACK.default_qr_blocksize(A)
198+
positive = true, pivoted = false, blocksize = YALAPACK.default_qr_blocksize(A)
199199
)
200200
m, n = size(A)
201201
minmn = min(m, n)
@@ -215,7 +215,7 @@ end
215215
# Diagonal logic
216216
# --------------
217217
function _diagonal_qr!(
218-
A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix; positive::Bool = false
218+
A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix; positive::Bool = true
219219
)
220220
# note: Ad and Qd might share memory here so order of operations is important
221221
Ad = diagview(A)
@@ -231,7 +231,7 @@ function _diagonal_qr!(
231231
return Q, R
232232
end
233233

234-
_diagonal_qr_null!(A::AbstractMatrix, N; positive::Bool = false) = N
234+
_diagonal_qr_null!(A::AbstractMatrix, N; positive::Bool = true) = N
235235

236236
# GPU logic
237237
# --------------
@@ -269,7 +269,7 @@ function _gpu_unmqr!(
269269
end
270270

271271
function _gpu_qr!(
272-
A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix; positive = false, blocksize = 1, pivoted = false
272+
A::AbstractMatrix, Q::AbstractMatrix, R::AbstractMatrix; positive = true, blocksize = 1, pivoted = false
273273
)
274274
blocksize > 1 &&
275275
throw(ArgumentError("CUSOLVER/ROCSOLVER does not provide a blocked implementation for a QR decomposition"))
@@ -310,7 +310,7 @@ function _gpu_qr!(
310310
end
311311

312312
function _gpu_qr_null!(
313-
A::AbstractMatrix, N::AbstractMatrix; positive = false, blocksize = 1, pivoted = false
313+
A::AbstractMatrix, N::AbstractMatrix; positive = true, blocksize = 1, pivoted = false
314314
)
315315
blocksize > 1 &&
316316
throw(ArgumentError("CUSOLVER/ROCSOLVER does not provide a blocked implementation for a QR decomposition"))

src/interface/decompositions.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,34 @@ by construction.
2828
@algdef Native_HouseholderLQ
2929

3030
"""
31-
LAPACK_HouseholderQR(; blocksize, positive = false, pivoted = false)
31+
LAPACK_HouseholderQR(; blocksize, positive = true, pivoted = false)
3232
3333
Algorithm type to denote the standard LAPACK algorithm for computing the QR decomposition of
3434
a matrix using Householder reflectors. The specific LAPACK function can be controlled using
3535
the keyword arugments, i.e. `?geqrt` will be chosen if `blocksize > 1`. With
3636
`blocksize == 1`, `?geqrf` will be chosen if `pivoted == false` and `?geqp3` will be chosen
37-
if `pivoted == true`. The keyword `positive = true` can be used to ensure that the diagonal
37+
if `pivoted == true`. The keyword `positive = true` is used to ensure that the diagonal
3838
elements of `R` are non-negative.
3939
"""
4040
@algdef LAPACK_HouseholderQR
4141

4242
"""
43-
LAPACK_HouseholderLQ(; blocksize, positive = false)
43+
LAPACK_HouseholderLQ(; blocksize, positive = true)
4444
4545
Algorithm type to denote the standard LAPACK algorithm for computing the LQ decomposition of
4646
a matrix using Householder reflectors. The specific LAPACK function can be controlled using
4747
the keyword arugments, i.e. `?gelqt` will be chosen if `blocksize > 1` or `?gelqf` will be
48-
chosen if `blocksize == 1`. The keyword `positive = true` can be used to ensure that the diagonal
49-
elements of `L` are non-negative.
48+
chosen if `blocksize == 1`. The keyword `positive = true` is used to ensure that the
49+
diagonal elements of `L` are non-negative.
5050
"""
5151
@algdef LAPACK_HouseholderLQ
5252

5353
"""
54-
GLA_HouseholderQR(; positive = false)
54+
GLA_HouseholderQR(; positive = true)
5555
5656
Algorithm type to denote the GenericLinearAlgebra.jl implementation for computing the QR decomposition
5757
of a matrix using Householder reflectors. Currently, only `blocksize = 1` and `pivoted == false`
58-
are supported. The keyword `positive = true` can be used to ensure that the diagonal elements
58+
are supported. The keyword `positive = true` is used to ensure that the diagonal elements
5959
of `R` are non-negative.
6060
"""
6161
@algdef GLA_HouseholderQR
@@ -230,7 +230,7 @@ end
230230
# CUSOLVER ALGORITHMS
231231
# =========================
232232
"""
233-
CUSOLVER_HouseholderQR(; positive = false)
233+
CUSOLVER_HouseholderQR(; positive = true)
234234
235235
Algorithm type to denote the standard CUSOLVER algorithm for computing the QR decomposition of
236236
a matrix using Householder reflectors. The keyword `positive = true` can be used to ensure that
@@ -318,10 +318,10 @@ const CUSOLVER_SVDAlgorithm = Union{
318318
# ROCSOLVER ALGORITHMS
319319
# =========================
320320
"""
321-
ROCSOLVER_HouseholderQR(; positive = false)
321+
ROCSOLVER_HouseholderQR(; positive = true)
322322
323323
Algorithm type to denote the standard ROCSOLVER algorithm for computing the QR decomposition of
324-
a matrix using Householder reflectors. The keyword `positive=true` can be used to ensure that
324+
a matrix using Householder reflectors. The keyword `positive = true` is used to ensure that
325325
the diagonal elements of `R` are non-negative.
326326
"""
327327
@algdef ROCSOLVER_HouseholderQR

0 commit comments

Comments
 (0)