Skip to content

Commit ad68891

Browse files
committed
Use Preferences to toggle precompilation of code that requires GPL dependencies
1 parent 0857619 commit ad68891

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ KLU = "ef3ab10e-7fda-4108-b977-705223b18434"
1313
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
1414
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
1515
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
16+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1617
RecursiveFactorization = "f2c3362d-daeb-58d1-803e-2bc74f2840b4"
1718
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1819
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
@@ -31,6 +32,7 @@ IterativeSolvers = "0.9.2"
3132
KLU = "0.3.0, 0.4"
3233
Krylov = "0.9"
3334
KrylovKit = "0.5, 0.6"
35+
Preferences = "1"
3436
RecursiveFactorization = "0.2.8"
3537
Reexport = "1"
3638
SciMLBase = "1.68"

src/LinearSolve.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using KLU
1515
using FastLapackInterface
1616
using DocStringExtensions
1717
import GPUArraysCore
18+
import Preferences
1819

1920
# wrap
2021
import Krylov
@@ -47,6 +48,11 @@ include("solve_function.jl")
4748
include("default.jl")
4849
include("init.jl")
4950

51+
const INCLUDE_SPARSE = Preferences.@load_preference("include_sparse", Base.USE_GPL_LIBS)
52+
@static if INCLUDE_SPARSE
53+
include("factorization_sparse.jl")
54+
end
55+
5056
const IS_OPENBLAS = Ref(true)
5157
isopenblas() = IS_OPENBLAS[]
5258

@@ -60,12 +66,17 @@ SnoopPrecompile.@precompile_all_calls begin
6066
sol = solve(prob, LUFactorization())
6167
sol = solve(prob, RFLUFactorization())
6268
sol = solve(prob, KrylovJL_GMRES())
69+
end
6370

64-
A = sprand(4, 4, 0.3) + I
65-
prob = LinearProblem(A, b)
66-
sol = solve(prob)
67-
sol = solve(prob, KLUFactorization())
68-
sol = solve(prob, UMFPACKFactorization())
71+
@static if INCLUDE_SPARSE
72+
SnoopPrecompile.@precompile_all_calls begin
73+
A = sprand(4, 4, 0.3) + I
74+
b = rand(4)
75+
prob = LinearProblem(A, b)
76+
sol = solve(prob)
77+
sol = solve(prob, KLUFactorization())
78+
sol = solve(prob, UMFPACKFactorization())
79+
end
6980
end
7081

7182
export LUFactorization, SVDFactorization, QRFactorization, GenericFactorization,

src/factorization.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ function _ldiv!(x::Vector, A::Factorization, b::Vector)
55
ldiv!(A, x)
66
end
77

8-
# Specialize QR for the non-square case
9-
# Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242
10-
function _ldiv!(x::Vector,
11-
A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY,
12-
SuiteSparse.SPQR.QRSparse}, b::Vector)
13-
x .= A \ b
14-
end
15-
168
function SciMLBase.solve(cache::LinearCache, alg::AbstractFactorization; kwargs...)
179
if cache.isfresh
1810
fact = do_factorization(alg, cache.A, cache.b, cache.u)

src/factorization_sparse.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Specialize QR for the non-square case
2+
# Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242
3+
function _ldiv!(x::Vector,
4+
A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY,
5+
SuiteSparse.SPQR.QRSparse}, b::Vector)
6+
x .= A \ b
7+
end

0 commit comments

Comments
 (0)