Skip to content

Commit 5e75cfe

Browse files
tkfandreasnoack
authored andcommitted
Add blocksize keyword argument to qr[!] (#33053)
1 parent c1e2760 commit 5e75cfe

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Standard library changes
3232

3333
#### LinearAlgebra
3434

35+
* `qr` and `qr!` functions support `blocksize` keyword argument ([#33053]).
36+
3537

3638
#### SparseArrays
3739

stdlib/LinearAlgebra/src/qr.jl

+16-12
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,23 @@ function qrfactPivotedUnblocked!(A::StridedMatrix)
246246
end
247247

248248
# LAPACK version
249-
qr!(A::StridedMatrix{<:BlasFloat}, ::Val{false}) = QRCompactWY(LAPACK.geqrt!(A, min(min(size(A)...), 36))...)
249+
qr!(A::StridedMatrix{<:BlasFloat}, ::Val{false} = Val(false); blocksize=36) =
250+
QRCompactWY(LAPACK.geqrt!(A, min(min(size(A)...), blocksize))...)
250251
qr!(A::StridedMatrix{<:BlasFloat}, ::Val{true}) = QRPivoted(LAPACK.geqp3!(A)...)
251-
qr!(A::StridedMatrix{<:BlasFloat}) = qr!(A, Val(false))
252252

253253
# Generic fallbacks
254254

255255
"""
256-
qr!(A, pivot=Val(false))
256+
qr!(A, pivot=Val(false); blocksize)
257257
258258
`qr!` is the same as [`qr`](@ref) when `A` is a subtype of
259259
`StridedMatrix`, but saves space by overwriting the input `A`, instead of creating a copy.
260260
An [`InexactError`](@ref) exception is thrown if the factorization produces a number not
261261
representable by the element type of `A`, e.g. for integer types.
262262
263+
!!! compat "Julia 1.4"
264+
The `blocksize` keyword argument requires Julia 1.4 or later.
265+
263266
# Examples
264267
```jldoctest
265268
julia> a = [1. 2.; 3. 4.]
@@ -296,7 +299,7 @@ qr!(A::StridedMatrix) = qr!(A, Val(false))
296299
_qreltype(::Type{T}) where T = typeof(zero(T)/sqrt(abs2(one(T))))
297300

298301
"""
299-
qr(A, pivot=Val(false)) -> F
302+
qr(A, pivot=Val(false); blocksize) -> F
300303
301304
Compute the QR factorization of the matrix `A`: an orthogonal (or unitary if `A` is
302305
complex-valued) matrix `Q`, and an upper triangular matrix `R` such that
@@ -336,6 +339,13 @@ and `F.Q*A` are supported. A `Q` matrix can be converted into a regular matrix w
336339
`m`×`m` orthogonal matrix, use `F.Q*Matrix(I,m,m)`. If `m<=n`, then `Matrix(F.Q)` yields an `m`×`m`
337340
orthogonal matrix.
338341
342+
The block size for QR decomposition can be specified by keyword argument
343+
`blocksize :: Integer` when `pivot == Val(false)` and `A isa StridedMatrix{<:BlasFloat}`.
344+
It is ignored when `blocksize > minimum(size(A))`. See [`QRCompactWY`](@ref).
345+
346+
!!! compat "Julia 1.4"
347+
The `blocksize` keyword argument requires Julia 1.4 or later.
348+
339349
# Examples
340350
```jldoctest
341351
julia> A = [3.0 -6.0; 4.0 -8.0; 0.0 1.0]
@@ -366,17 +376,11 @@ true
366376
elementary reflectors, so that the `Q` and `R` matrices can be stored
367377
compactly rather as two separate dense matrices.
368378
"""
369-
function qr(A::AbstractMatrix{T}, arg) where T
370-
require_one_based_indexing(A)
371-
AA = similar(A, _qreltype(T), size(A))
372-
copyto!(AA, A)
373-
return qr!(AA, arg)
374-
end
375-
function qr(A::AbstractMatrix{T}) where T
379+
function qr(A::AbstractMatrix{T}, arg...; kwargs...) where T
376380
require_one_based_indexing(A)
377381
AA = similar(A, _qreltype(T), size(A))
378382
copyto!(AA, A)
379-
return qr!(AA)
383+
return qr!(AA, arg...; kwargs...)
380384
end
381385
qr(x::Number) = qr(fill(x,1,1))
382386
function qr(v::AbstractVector)

0 commit comments

Comments
 (0)