From e2b9740618045f1506d663101aa385cce286468e Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 12 May 2025 16:12:16 +0000 Subject: [PATCH] Fix SparseMatrixCSC with alternative Integer types Fixes https://github.com/SciML/NonlinearSolve.jl/issues/599 --- ext/ArrayInterfaceSparseArraysExt.jl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/ArrayInterfaceSparseArraysExt.jl b/ext/ArrayInterfaceSparseArraysExt.jl index 61fff69d..9f0e06b4 100644 --- a/ext/ArrayInterfaceSparseArraysExt.jl +++ b/ext/ArrayInterfaceSparseArraysExt.jl @@ -14,25 +14,25 @@ function findstructralnz(x::SparseMatrixCSC) (rowind, colind) end -function bunchkaufman_instance(A::SparseMatrixCSC) - bunchkaufman(sparse(similar(A, 1, 1)), check = false) +function bunchkaufman_instance(A::SparseMatrixCSC{Tv, Ti}) where {Tv, Ti} + bunchkaufman(SparseMatrixCSC{Tv, Ti}(similar(A, 1, 1)), check = false) end -function cholesky_instance(A::Union{SparseMatrixCSC,Symmetric{<:Number,<:SparseMatrixCSC}}, pivot = DEFAULT_CHOLESKY_PIVOT) - cholesky(sparse(similar(A, 1, 1)), check = false) +function cholesky_instance(A::Union{SparseMatrixCSC{Tv, Ti},Symmetric{<:Number,<:SparseMatrixCSC{Tv, Ti}}}, pivot = DEFAULT_CHOLESKY_PIVOT) where {Tv, Ti} + cholesky(SparseMatrixCSC{Tv, Ti}(similar(A, 1, 1)), check = false) end -function ldlt_instance(A::SparseMatrixCSC) - ldlt(sparse(similar(A, 1, 1)), check=false) +function ldlt_instance(A::SparseMatrixCSC{Tv, Ti}) where {Tv, Ti} + ldlt(SparseMatrixCSC{Tv, Ti}(similar(A, 1, 1)), check=false) end # Could be optimized but this should work for any real case. -function lu_instance(jac_prototype::SparseMatrixCSC, pivot = DEFAULT_CHOLESKY_PIVOT) - lu(sparse(rand(1,1))) +function lu_instance(jac_prototype::SparseMatrixCSC{Tv, Ti}, pivot = DEFAULT_CHOLESKY_PIVOT) where {Tv, Ti} + lu(SparseMatrixCSC{Tv, Ti}(rand(1,1))) end -function qr_instance(jac_prototype::SparseMatrixCSC, pivot = DEFAULT_CHOLESKY_PIVOT) - qr(sparse(rand(1,1))) +function qr_instance(jac_prototype::SparseMatrixCSC{Tv, Ti}, pivot = DEFAULT_CHOLESKY_PIVOT) where {Tv, Ti} + qr(SparseMatrixCSC{Tv, Ti}(rand(1,1))) end end