-
-
Notifications
You must be signed in to change notification settings - Fork 72
Setup the codebase to use explicit imports #636
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
Changes from 3 commits
21adabe
2889418
2b48908
1a846f5
7a4c3bd
e4f58bb
a5c124e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,8 @@ | ||||||||||
module LinearSolveEnzymeExt | ||||||||||
|
||||||||||
using LinearSolve | ||||||||||
using LinearSolve: LinearSolve, SciMLLinearSolveAlgorithm, init, solve!, LinearProblem, | ||||||||||
LinearCache, AbstractKrylovSubspaceMethod, DefaultLinearSolver, | ||||||||||
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
defaultalg_adjoint_eval | ||||||||||
using LinearSolve.LinearAlgebra | ||||||||||
using EnzymeCore | ||||||||||
using EnzymeCore: EnzymeRules | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,8 @@ | ||||||||
module LinearSolveRecursiveFactorizationExt | ||||||||
|
||||||||
using LinearSolve | ||||||||
using LinearSolve: LinearSolve, userecursivefactorization, LinearCache, @get_cacheval, RFLUFactorization | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
using LinearSolve.LinearAlgebra, LinearSolve.ArrayInterface, RecursiveFactorization | ||||||||
using SciMLBase: SciMLBase, ReturnCode | ||||||||
|
||||||||
LinearSolve.userecursivefactorization(A::Union{Nothing, AbstractMatrix}) = true | ||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,9 +1,17 @@ | ||||||||||||||||||
module LinearSolveSparseArraysExt | ||||||||||||||||||
|
||||||||||||||||||
using LinearSolve, LinearAlgebra | ||||||||||||||||||
using SparseArrays | ||||||||||||||||||
using SparseArrays: AbstractSparseMatrixCSC, nonzeros, rowvals, getcolptr | ||||||||||||||||||
using LinearSolve: BLASELTYPES, pattern_changed, ArrayInterface | ||||||||||||||||||
using LinearSolve: LinearSolve, BLASELTYPES, pattern_changed, ArrayInterface, | ||||||||||||||||||
@get_cacheval, CHOLMODFactorization, GenericFactorization, GenericLUFactorization, | ||||||||||||||||||
KLUFactorization, LUFactorization, NormalCholeskyFactorization, OperatorAssumptions, | ||||||||||||||||||
QRFactorization, RFLUFactorization, UMFPACKFactorization, solve | ||||||||||||||||||
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||
using ArrayInterface: ArrayInterface | ||||||||||||||||||
using LinearAlgebra: LinearAlgebra, I, Hermitian, Symmetric, cholesky, ldiv!, lu, lu!, QR | ||||||||||||||||||
using SparseArrays: SparseArrays, AbstractSparseArray, AbstractSparseMatrixCSC, SparseMatrixCSC, | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||
nonzeros, rowvals, getcolptr, sparse, sprand | ||||||||||||||||||
using SparseArrays.UMFPACK: UMFPACK_OK | ||||||||||||||||||
using Base: /, \, convert | ||||||||||||||||||
using SciMLBase: SciMLBase, LinearProblem, ReturnCode | ||||||||||||||||||
import StaticArraysCore: SVector | ||||||||||||||||||
|
||||||||||||||||||
# Can't `using KLU` because cannot have a dependency in there without | ||||||||||||||||||
# requiring the user does `using KLU` | ||||||||||||||||||
|
@@ -187,7 +195,7 @@ function SciMLBase.solve!( | |||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
F = LinearSolve.@get_cacheval(cache, :UMFPACKFactorization) | ||||||||||||||||||
if F.status == SparseArrays.UMFPACK.UMFPACK_OK | ||||||||||||||||||
if F.status == UMFPACK_OK | ||||||||||||||||||
y = ldiv!(cache.u, F, cache.b) | ||||||||||||||||||
SciMLBase.build_linear_solution(alg, y, nothing, cache; retcode = ReturnCode.Success) | ||||||||||||||||||
else | ||||||||||||||||||
|
@@ -298,36 +306,36 @@ function LinearSolve.init_cacheval(alg::NormalCholeskyFactorization, | |||||||||||||||||
Symmetric{T, <:AbstractSparseArray{T}}}, b, u, Pl, Pr, | ||||||||||||||||||
maxiters::Int, abstol, reltol, verbose::Bool, | ||||||||||||||||||
assumptions::OperatorAssumptions) where {T <: BLASELTYPES} | ||||||||||||||||||
LinearSolve.ArrayInterface.cholesky_instance(convert(AbstractMatrix, A)) | ||||||||||||||||||
ArrayInterface.cholesky_instance(convert(AbstractMatrix, A)) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
# Specialize QR for the non-square case | ||||||||||||||||||
# Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242 | ||||||||||||||||||
function LinearSolve._ldiv!(x::Vector, | ||||||||||||||||||
A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY, | ||||||||||||||||||
A::Union{QR, LinearAlgebra.QRCompactWY, | ||||||||||||||||||
SparseArrays.SPQR.QRSparse, | ||||||||||||||||||
SparseArrays.CHOLMOD.Factor}, b::Vector) | ||||||||||||||||||
x .= A \ b | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
function LinearSolve._ldiv!(x::AbstractVector, | ||||||||||||||||||
A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY, | ||||||||||||||||||
A::Union{QR, LinearAlgebra.QRCompactWY, | ||||||||||||||||||
SparseArrays.SPQR.QRSparse, | ||||||||||||||||||
SparseArrays.CHOLMOD.Factor}, b::AbstractVector) | ||||||||||||||||||
x .= A \ b | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
# Ambiguity removal | ||||||||||||||||||
function LinearSolve._ldiv!(::LinearSolve.SVector, | ||||||||||||||||||
function LinearSolve._ldiv!(::SVector, | ||||||||||||||||||
A::Union{SparseArrays.CHOLMOD.Factor, LinearAlgebra.QR, | ||||||||||||||||||
LinearAlgebra.QRCompactWY, SparseArrays.SPQR.QRSparse}, | ||||||||||||||||||
b::AbstractVector) | ||||||||||||||||||
(A \ b) | ||||||||||||||||||
end | ||||||||||||||||||
function LinearSolve._ldiv!(::LinearSolve.SVector, | ||||||||||||||||||
function LinearSolve._ldiv!(::SVector, | ||||||||||||||||||
A::Union{SparseArrays.CHOLMOD.Factor, LinearAlgebra.QR, | ||||||||||||||||||
LinearAlgebra.QRCompactWY, SparseArrays.SPQR.QRSparse}, | ||||||||||||||||||
b::LinearSolve.SVector) | ||||||||||||||||||
b::SVector) | ||||||||||||||||||
(A \ b) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -360,16 +368,10 @@ function LinearSolve.init_cacheval( | |||||||||||||||||
nothing | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
function LinearSolve.init_cacheval(alg::QRFactorization, A::SparseMatrixCSC{Float64, Int}, b, u, Pl, Pr, | ||||||||||||||||||
function LinearSolve.init_cacheval(alg::QRFactorization, A::SparseMatrixCSC{Float64, <:Integer}, b, u, Pl, Pr, | ||||||||||||||||||
maxiters::Int, abstol, reltol, verbose::Bool, | ||||||||||||||||||
assumptions::OperatorAssumptions) | ||||||||||||||||||
LinearSolve.ArrayInterface.qr_instance(convert(AbstractMatrix, A), alg.pivot) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
function LinearSolve.init_cacheval(alg::QRFactorization, A::SparseMatrixCSC{Float64, Int32}, b, u, Pl, Pr, | ||||||||||||||||||
maxiters::Int, abstol, reltol, verbose::Bool, | ||||||||||||||||||
assumptions::OperatorAssumptions) | ||||||||||||||||||
LinearSolve.ArrayInterface.qr_instance(convert(AbstractMatrix, A), alg.pivot) | ||||||||||||||||||
ArrayInterface.qr_instance(convert(AbstractMatrix, A), alg.pivot) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
function LinearSolve.init_cacheval( | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,27 +5,33 @@ if isdefined(Base, :Experimental) && | |||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import PrecompileTools | ||||||||||||||||||||||||||||||
using ArrayInterface | ||||||||||||||||||||||||||||||
using Base: cache_dependencies, Bool | ||||||||||||||||||||||||||||||
using LinearAlgebra | ||||||||||||||||||||||||||||||
using ArrayInterface: ArrayInterface | ||||||||||||||||||||||||||||||
using Base: Bool, convert, copyto!, adjoint, transpose, /, \, require_one_based_indexing | ||||||||||||||||||||||||||||||
using LinearAlgebra: LinearAlgebra, BlasInt, LU, Adjoint, BLAS, Bidiagonal, BunchKaufman, | ||||||||||||||||||||||||||||||
ColumnNorm, Diagonal, Factorization, Hermitian, I, LAPACK, NoPivot, | ||||||||||||||||||||||||||||||
RowMaximum, RowNonZero, SymTridiagonal, Symmetric, Transpose, | ||||||||||||||||||||||||||||||
Tridiagonal, UniformScaling, axpby!, axpy!, bunchkaufman, bunchkaufman!, | ||||||||||||||||||||||||||||||
cholesky, cholesky!, diagind, dot, inv, ldiv!, ldlt!, lu, lu!, mul!, norm, | ||||||||||||||||||||||||||||||
qr, qr!, svd, svd! | ||||||||||||||||||||||||||||||
Comment on lines
+10
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||
using LazyArrays: @~, BroadcastArray | ||||||||||||||||||||||||||||||
using SciMLBase: AbstractLinearAlgorithm, LinearAliasSpecifier | ||||||||||||||||||||||||||||||
using SciMLOperators | ||||||||||||||||||||||||||||||
using SciMLOperators: AbstractSciMLOperator, IdentityOperator | ||||||||||||||||||||||||||||||
using Setfield | ||||||||||||||||||||||||||||||
using UnPack | ||||||||||||||||||||||||||||||
using DocStringExtensions | ||||||||||||||||||||||||||||||
using EnumX | ||||||||||||||||||||||||||||||
using Markdown | ||||||||||||||||||||||||||||||
using ChainRulesCore | ||||||||||||||||||||||||||||||
using SciMLBase: SciMLBase, LinearAliasSpecifier, AbstractSciMLOperator, | ||||||||||||||||||||||||||||||
init, solve!, reinit!, solve, ReturnCode, LinearProblem | ||||||||||||||||||||||||||||||
using SciMLOperators: SciMLOperators, AbstractSciMLOperator, IdentityOperator, MatrixOperator, | ||||||||||||||||||||||||||||||
has_ldiv!, issquare | ||||||||||||||||||||||||||||||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||
using Setfield: @set, @set! | ||||||||||||||||||||||||||||||
using UnPack: @unpack | ||||||||||||||||||||||||||||||
using DocStringExtensions: DocStringExtensions | ||||||||||||||||||||||||||||||
using EnumX: EnumX, @enumx | ||||||||||||||||||||||||||||||
using Markdown: Markdown, @doc_str | ||||||||||||||||||||||||||||||
using ChainRulesCore: ChainRulesCore | ||||||||||||||||||||||||||||||
using Reexport: Reexport, @reexport | ||||||||||||||||||||||||||||||
using Libdl: Libdl, dlsym_e | ||||||||||||||||||||||||||||||
import InteractiveUtils | ||||||||||||||||||||||||||||||
import RecursiveArrayTools | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import StaticArraysCore: StaticArray, SVector, MVector, SMatrix, MMatrix | ||||||||||||||||||||||||||||||
import StaticArraysCore: StaticArray, SVector, SMatrix | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
using LinearAlgebra: BlasInt, LU | ||||||||||||||||||||||||||||||
using LinearAlgebra.LAPACK: require_one_based_indexing, | ||||||||||||||||||||||||||||||
chkfinite, chkstride1, | ||||||||||||||||||||||||||||||
using LinearAlgebra.LAPACK: chkfinite, chkstride1, | ||||||||||||||||||||||||||||||
@blasfunc, chkargsok | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import GPUArraysCore | ||||||||||||||||||||||||||||||
|
@@ -34,8 +40,6 @@ import ConcreteStructs: @concrete | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
# wrap | ||||||||||||||||||||||||||||||
import Krylov | ||||||||||||||||||||||||||||||
using SciMLBase | ||||||||||||||||||||||||||||||
import Preferences | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const CRC = ChainRulesCore | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
@@ -51,9 +55,7 @@ else | |||||||||||||||||||||||||||||
const usemkl = false | ||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
using Reexport | ||||||||||||||||||||||||||||||
@reexport using SciMLBase | ||||||||||||||||||||||||||||||
using SciMLBase: _unwrap_val | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
abstract type SciMLLinearSolveAlgorithm <: SciMLBase.AbstractLinearAlgorithm end | ||||||||||||||||||||||||||||||
abstract type AbstractFactorization <: SciMLLinearSolveAlgorithm end | ||||||||||||||||||||||||||||||
|
@@ -95,6 +97,11 @@ issparsematrix(A) = false | |||||||||||||||||||||||||||||
make_SparseMatrixCSC(A) = nothing | ||||||||||||||||||||||||||||||
makeempty_SparseMatrixCSC(A) = nothing | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
# Stub functions for SparseArrays - overridden in extension | ||||||||||||||||||||||||||||||
getcolptr(A) = error("SparseArrays extension not loaded") | ||||||||||||||||||||||||||||||
rowvals(A) = error("SparseArrays extension not loaded") | ||||||||||||||||||||||||||||||
nonzeros(A) = error("SparseArrays extension not loaded") | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
EnumX.@enumx DefaultAlgorithmChoice begin | ||||||||||||||||||||||||||||||
LUFactorization | ||||||||||||||||||||||||||||||
QRFactorization | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,6 @@ | ||||||||||
using LinearSolve, Aqua | ||||||||||
using ExplicitImports | ||||||||||
|
||||||||||
@testset "Aqua" begin | ||||||||||
Aqua.find_persistent_tasks_deps(LinearSolve) | ||||||||||
Aqua.test_ambiguities(LinearSolve, recursive = false, broken = true) | ||||||||||
|
@@ -10,3 +12,21 @@ using LinearSolve, Aqua | |||||||||
Aqua.test_unbound_args(LinearSolve) | ||||||||||
Aqua.test_undefined_exports(LinearSolve) | ||||||||||
end | ||||||||||
|
||||||||||
@testset "Explicit Imports" begin | ||||||||||
# Get extension modules that might be unanalyzable | ||||||||||
klu_mod = try | ||||||||||
Base.get_extension(LinearSolve, :LinearSolveSparseArraysExt).KLU | ||||||||||
catch | ||||||||||
nothing | ||||||||||
end | ||||||||||
unanalyzable_mods = (LinearSolve.OperatorCondition, LinearSolve.DefaultAlgorithmChoice) | ||||||||||
if klu_mod !== nothing | ||||||||||
unanalyzable_mods = (unanalyzable_mods..., klu_mod) | ||||||||||
end | ||||||||||
|
||||||||||
@test check_no_implicit_imports(LinearSolve; skip = (Base, Core), | ||||||||||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
allow_unanalyzable = unanalyzable_mods) === nothing | ||||||||||
@test check_no_stale_explicit_imports(LinearSolve; allow_unanalyzable = unanalyzable_mods) === nothing | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
@test check_all_qualified_accesses_via_owners(LinearSolve) === nothing | ||||||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶