Skip to content

Commit 8bab09a

Browse files
Merge pull request #244 from SciML/sparsearrays
Make sparsearrays into a weak dep ext
2 parents 3da405c + cc22efc commit 8bab09a

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
name = "SciMLOperators"
22
uuid = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
33
authors = ["Vedant Puri <vedantpuri@gmail.com>"]
4-
version = "0.3.8"
4+
version = "0.3.9"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
88
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1111
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
12-
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1312
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
1413

14+
[weakdeps]
15+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
16+
1517
[compat]
1618
ArrayInterface = "7"
1719
DocStringExtensions = "0.8, 0.9"

ext/SciMLOperatorsSparseArraysExt.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module SciMLOperatorsSparseArraysExt
2+
3+
import SciMLOperators
4+
import SparseArrays: sparse, issparse
5+
import SparseArrays
6+
import LinearAlgebra
7+
8+
SparseArrays.sparse(L::SciMLOperators.MatrixOperator) = sparse(L.A)
9+
SparseArrays.issparse(L::SciMLOperators.MatrixOperator) = issparse(L.A)
10+
SparseArrays.sparse(L::SciMLOperators.ScaledOperator) = L.λ * sparse(L.L)
11+
SparseArrays.sparse(L::SciMLOperators.AddedOperator) = sum(sparse, L.ops)
12+
SparseArrays.sparse(L::SciMLOperators.ComposedOperator) = prod(sparse, L.ops)
13+
function SparseArrays.sparse(L::SciMLOperators.TensorProductOperator)
14+
LinearAlgebra.kron(sparse.(AbstractMatrix, L.ops)...)
15+
end
16+
17+
end

src/SciMLOperators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module SciMLOperators
66
using DocStringExtensions
77

88
using LinearAlgebra
9-
import SparseArrays
9+
1010
import StaticArraysCore
1111
import ArrayInterface
1212
import MacroTools: @forward
@@ -19,7 +19,7 @@ import Base: +, -, *, /, \, ∘, ==, conj, exp, kron
1919
import Base: iszero, inv, adjoint, transpose, size, convert
2020
import LinearAlgebra: mul!, ldiv!, lmul!, rmul!, factorize
2121
import LinearAlgebra: Matrix, Diagonal
22-
import SparseArrays: sparse, issparse
22+
2323

2424
"""
2525
$(TYPEDEF)

src/basic.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ Base.:+(L::AbstractSciMLOperator) = L
223223
function Base.convert(::Type{AbstractMatrix}, L::ScaledOperator)
224224
convert(Number, L.λ) * convert(AbstractMatrix, L.L)
225225
end
226-
SparseArrays.sparse(L::ScaledOperator) = L.λ * sparse(L.L)
227226

228227
# traits
229228
function Base.show(io::IO, L::ScaledOperator{T}) where {T}
@@ -382,7 +381,6 @@ end
382381
function Base.convert(::Type{AbstractMatrix}, L::AddedOperator)
383382
sum(op -> convert(AbstractMatrix, op), L.ops)
384383
end
385-
SparseArrays.sparse(L::AddedOperator) = sum(sparse, L.ops)
386384

387385
# traits
388386
function Base.show(io::IO, L::AddedOperator)
@@ -540,7 +538,6 @@ end
540538
function Base.convert(::Type{AbstractMatrix}, L::ComposedOperator)
541539
prod(op -> convert(AbstractMatrix, op), L.ops)
542540
end
543-
SparseArrays.sparse(L::ComposedOperator) = prod(sparse, L.ops)
544541

545542
# traits
546543
function Base.show(io::IO, L::ComposedOperator)

src/matrix.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ function update_coefficients!(L::MatrixOperator, u, p, t; kwargs...)
163163
L.update_func!(L.A, u, p, t; kwargs...)
164164
end
165165

166-
SparseArrays.sparse(L::MatrixOperator) = sparse(L.A)
167-
SparseArrays.issparse(L::MatrixOperator) = issparse(L.A)
168-
169166
# TODO - add tests for MatrixOperator indexing
170167
# propagate_inbounds here for the getindex fallback
171168
Base.@propagate_inbounds Base.convert(::Type{AbstractMatrix}, L::MatrixOperator) = convert(

src/tensor.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ function Base.convert(::Type{AbstractMatrix}, L::TensorProductOperator)
8282
kron(convert.(AbstractMatrix, L.ops)...)
8383
end
8484

85-
function SparseArrays.sparse(L::TensorProductOperator)
86-
kron(sparse.(AbstractMatrix, L.ops)...)
87-
end
85+
8886

8987
#LinearAlgebra.opnorm(L::TensorProductOperator) = prod(opnorm, L.ops)
9088

0 commit comments

Comments
 (0)