Skip to content

Fix cholesky_instance for symmetric sparse #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2023
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: 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.6"
version = "7.4.7"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
4 changes: 2 additions & 2 deletions src/ArrayInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,10 @@ cholesky_instance(A, pivot = LinearAlgebra.RowMaximum()) -> cholesky_factorizati
Returns an instance of the Cholesky factorization object with the correct type
cheaply.
"""
function cholesky_instance(A::Matrix{T}, pivot = LinearAlgebra.RowMaximum()) where {T}
function cholesky_instance(A::Matrix{T}, pivot = LinearAlgebra.NoPivot()) where {T}
return cholesky(similar(A, 0, 0), pivot, check = false)
Copy link
Collaborator

@chriselrod chriselrod May 30, 2023

Choose a reason for hiding this comment

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

I don't know about the sparse case, but it normally isn't necessary to pivot dense cholesky factorizations.

end
function cholesky_instance(A::SparseMatrixCSC, pivot = LinearAlgebra.RowMaximum())
function cholesky_instance(A::Union{SparseMatrixCSC,Symmetric{<:Number,<:SparseMatrixCSC}}, pivot = LinearAlgebra.RowMaximum())
cholesky(sparse(similar(A, 1, 1)), check = false)
end

Expand Down
15 changes: 12 additions & 3 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,19 @@ end
@test ArrayInterface.qr_instance(A) isa typeof(qr(A))

if !(eltype(A) <: BigFloat)
@test ArrayInterface.bunchkaufman_instance(A) isa typeof(bunchkaufman(A' * A))
@test ArrayInterface.cholesky_instance(A) isa typeof(cholesky(A' * A))
@test ArrayInterface.ldlt_instance(A) isa typeof(ldlt(SymTridiagonal(A' * A)))
@test ArrayInterface.bunchkaufman_instance(A' * A) isa typeof(bunchkaufman(A' * A))
@test ArrayInterface.cholesky_instance(A' * A) isa typeof(cholesky(A' * A))
@test ArrayInterface.ldlt_instance(SymTridiagonal(A' * A)) isa typeof(ldlt(SymTridiagonal(A' * A)))
@test ArrayInterface.svd_instance(A) isa typeof(svd(A))
end
end

for A in [sparse([1.0 2.0; 3.0 4.0])]
@test ArrayInterface.lu_instance(A) isa typeof(lu(A))
@test ArrayInterface.qr_instance(A) isa typeof(qr(A))
if VERSION >= v"1.9-"
@test ArrayInterface.cholesky_instance(A' * A) isa typeof(cholesky(A' * A))
end
@test ArrayInterface.ldlt_instance(SymTridiagonal(A' * A)) isa typeof(ldlt(SymTridiagonal(A' * A)))
end
end