Skip to content
Open
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
22 changes: 21 additions & 1 deletion ext/MatrixAlgebraKitGenericLinearAlgebraExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module MatrixAlgebraKitGenericLinearAlgebraExt

using MatrixAlgebraKit
using MatrixAlgebraKit: sign_safe, check_input, diagview, gaugefix!, default_fixgauge
using MatrixAlgebraKit: sign_safe, check_input, diagview, gaugefix!, one!, default_fixgauge
using GenericLinearAlgebra: svd!, svdvals!, eigen!, eigvals!, Hermitian, qr!
using LinearAlgebra: I, Diagonal, lmul!

Expand Down Expand Up @@ -72,6 +72,11 @@ function MatrixAlgebraKit.qr_compact!(A::AbstractMatrix, QR, alg::GLA_Householde
return _gla_householder_qr!(A, Q, R; alg.kwargs...)
end

function MatrixAlgebraKit.qr_null!(A::AbstractMatrix, N, alg::GLA_HouseholderQR)
check_input(qr_null!, A, N, alg)
return _gla_householder_qr_null!(A, N; alg.kwargs...)
end

function _gla_householder_qr!(A::AbstractMatrix, Q, R; positive = false, 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 @@ -109,6 +114,21 @@ function _gla_householder_qr!(A::AbstractMatrix, Q, R; positive = false, blocksi
return Q, R
end

function _gla_householder_qr_null!(
A::AbstractMatrix, N::AbstractMatrix;
positive = false, 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."))
m, n = size(A)
minmn = min(m, n)
fill!(N, zero(eltype(N)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fill!(N, zero(eltype(N)))
MatrixAlgebraKit.zero!(N)

Alternatively we can also just import this, but this is probably slightly more consistent

one!(view(N, (minmn + 1):m, 1:(m - minmn)))
Q̃, = qr!(A)
lmul!(Q̃, N)
return N
end

function MatrixAlgebraKit.default_lq_algorithm(::Type{T}; kwargs...) where {T <: StridedMatrix{<:Union{Float16, ComplexF16, BigFloat, Complex{BigFloat}}}}
return MatrixAlgebraKit.LQViaTransposedQR(GLA_HouseholderQR(; kwargs...))
end
Expand Down
4 changes: 2 additions & 2 deletions test/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ for T in (BLASFloats..., GenericFloats...), n in (37, m, 63)
)
TestSuite.test_lq_algs(T, (m, n), LAPACK_LQ_ALGS)
elseif T ∈ GenericFloats
TestSuite.test_lq(T, (m, n); test_null = false, test_pivoted = false, test_blocksize = false)
TestSuite.test_lq(T, (m, n); test_null = true, test_pivoted = false, test_blocksize = false)
GLA_LQ_ALGS = (LQViaTransposedQR(GLA_HouseholderQR()),)
TestSuite.test_lq_algs(T, (m, n), GLA_LQ_ALGS; test_null = false)
TestSuite.test_lq_algs(T, (m, n), GLA_LQ_ALGS; test_null = true)
end
if m == n
AT = Diagonal{T, Vector{T}}
Expand Down
2 changes: 1 addition & 1 deletion test/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ for T in (BLASFloats..., GenericFloats...), n in (37, m, 63)
)
TestSuite.test_qr_algs(T, (m, n), LAPACK_QR_ALGS)
elseif T ∈ GenericFloats
TestSuite.test_qr(T, (m, n); test_null = false, test_pivoted = false, test_blocksize = false)
TestSuite.test_qr(T, (m, n); test_null = true, test_pivoted = false, test_blocksize = false)
GLA_QR_ALGS = (GLA_HouseholderQR(),)
TestSuite.test_qr_algs(T, (m, n), GLA_QR_ALGS; test_null = false)
end
Expand Down
Loading