Skip to content

Commit

Permalink
Make SparseArrays an extension package
Browse files Browse the repository at this point in the history
While this may seem a bit weird since the most normal case for Krylov subspace methods is on sparse arrays, there are multiple reasons for this.

1. SparseArrays pulls in SuiteSparse and thus GPL dependencies
2. This is by far the biggest part of the load. Normal Krylov.jl loads in about 8ms, but the SparseArrays part is ~150ms. So if you want to just work on operators, then you'd taking a decently sized hit.
3. This is required for downstream dependency reduction SciML/LinearSolve.jl#570
  • Loading branch information
ChrisRackauckas authored and amontoison committed Feb 15, 2025
1 parent f03bafb commit 6b1f40f
Show file tree
Hide file tree
Showing 8 changed files with 865 additions and 941 deletions.
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[weakdeps]
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[extensions]
KrylovSparseArraysExt = "SparseArrays"

[compat]
julia = "1.6"
LinearAlgebra = "1.6"
Expand All @@ -17,7 +23,8 @@ Test = "1.6"

[extras]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Random", "Test"]
test = ["Random", "SparseArrays", "Test"]
20 changes: 20 additions & 0 deletions ext/KrylovSparseArraysExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module KrylovSparseArraysExt

using Krylov, SparseArrays
using Krylov.LinearAlgebra
using Krylov.LinearAlgebra: NoPivot, LowerTriangular
using Krylov: FloatOrComplex, reduced_qr!, ktypeof, vector_to_matrix, knorm, kdot, kaxpy!, kdotr, kfill!

function Krylov.ktypeof(v::S) where S <: SparseVector
T = eltype(S)
return Vector{T}
end

function Krylov.ktypeof(v::S) where S <: AbstractSparseVector
return S.types[2] # return `CuVector` for a `CuSparseVector`
end

include("krylov_processes.jl")
include("block_krylov_processes.jl")

end
Loading

0 comments on commit 6b1f40f

Please sign in to comment.