Skip to content

Commit

Permalink
Merge pull request #420 from JuliaArrays/qrpivot
Browse files Browse the repository at this point in the history
Allow for setting QR pivot types
  • Loading branch information
ChrisRackauckas authored Jun 19, 2023
2 parents 92400fa + 08aebd3 commit e5bd756
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ArrayInterface"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "7.4.10"
version = "7.4.11"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
18 changes: 11 additions & 7 deletions src/ArrayInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -622,21 +622,25 @@ else
end

"""
qr_instance(A) -> qr_factorization_instance
qr_instance(A, pivot = NoPivot()) -> qr_factorization_instance
Returns an instance of the QR factorization object with the correct type
cheaply.
"""
function qr_instance(A::Matrix{T}) where {T}
LinearAlgebra.QRCompactWY(zeros(T,0,0),zeros(T,0,0))
function qr_instance(A::Matrix{T},pivot = DEFAULT_CHOLESKY_PIVOT) where {T}
if pivot === DEFAULT_CHOLESKY_PIVOT
LinearAlgebra.QRCompactWY(zeros(T,0,0),zeros(T,0,0))
else
LinearAlgebra.QRPivoted(zeros(T,0,0),zeros(T,0),zeros(Int,0))
end
end

function qr_instance(A::Matrix{BigFloat})
function qr_instance(A::Matrix{BigFloat},pivot = DEFAULT_CHOLESKY_PIVOT)
LinearAlgebra.QR(zeros(BigFloat,0,0),zeros(BigFloat,0))
end

# Could be optimized but this should work for any real case.
function qr_instance(jac_prototype::SparseMatrixCSC)
function qr_instance(jac_prototype::SparseMatrixCSC, pivot = DEFAULT_CHOLESKY_PIVOT)
qr(sparse(rand(1,1)))
end

Expand All @@ -645,15 +649,15 @@ end
Returns the number.
"""
qr_instance(a::Number) = a
qr_instance(a::Number, pivot = DEFAULT_CHOLESKY_PIVOT) = a

"""
qr_instance(a::Any) -> qr(a)
Slow fallback which gets the instance via factorization. Should get
specialized for new matrix types.
"""
qr_instance(a::Any) = qr(a)# check = false)
qr_instance(a::Any, pivot = DEFAULT_CHOLESKY_PIVOT) = qr(a)# check = false)

"""
svd_instance(A) -> qr_factorization_instance
Expand Down

0 comments on commit e5bd756

Please sign in to comment.