Skip to content

Commit

Permalink
Allow linsolve to be \
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Jan 24, 2024
1 parent e989b72 commit c2791b9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NonlinearSolve"
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
authors = ["SciML"]
version = "3.5.0"
version = "3.5.1"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
15 changes: 5 additions & 10 deletions src/internal/linear_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,11 @@ function reinit_cache!(cache::LinearSolverCache, args...; kwargs...)
cache.nfactors = 0
end

@inline function LinearSolverCache(alg, linsolve, A::Number, b::Number, u; kwargs...)
return LinearSolverCache(nothing, nothing, A, b, nothing, 0, 0)
end
@inline function LinearSolverCache(alg, ::Nothing, A::SMatrix, b, u; kwargs...)
# Default handling for SArrays caching in LinearSolve is not the best. Override it here
return LinearSolverCache(nothing, nothing, A, b, nothing, 0, 0)
end
@inline function LinearSolverCache(alg, linsolve, A::Diagonal, b, u; kwargs...)
return LinearSolverCache(nothing, nothing, A, b, nothing, 0, 0)
end
function LinearSolverCache(alg, linsolve, A, b, u; kwargs...)
if (A isa Number && b isa Number) || (linsolve === nothing && A isa SMatrix) ||
(A isa Diagonal) || (linsolve isa typeof(\))
return LinearSolverCache(nothing, nothing, A, b, nothing, 0, 0)
end
@bb b_ = copy(b)
@bb u_ = copy(u)
linprob = LinearProblem(A, b_; u0 = u_, kwargs...)
Expand Down Expand Up @@ -193,3 +187,4 @@ end
@inline __needs_square_A(::Nothing, ::Number) = false
@inline __needs_square_A(::Nothing, _) = false
@inline __needs_square_A(linsolve, _) = LinearSolve.needs_square_A(linsolve)
@inline __needs_square_A(::typeof(\), _) = false

Check warning on line 190 in src/internal/linear_solve.jl

View check run for this annotation

Codecov / codecov/patch

src/internal/linear_solve.jl#L190

Added line #L190 was not covered by tests
1 change: 1 addition & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ end
end

@inline __needs_concrete_A(::Nothing) = false
@inline __needs_concrete_A(::typeof(\)) = true

Check warning on line 21 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L21

Added line #L21 was not covered by tests
@inline __needs_concrete_A(linsolve) = needs_concrete_A(linsolve)

@inline __maybe_mutable(x, ::AutoSparseEnzyme) = __mutable(x)
Expand Down
6 changes: 3 additions & 3 deletions test/core/rootfind.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const TERMINATION_CONDITIONS = [
]

@testset "[IIP] u0: $(typeof(u0)) precs: $(_nameof(prec)) linsolve: $(_nameof(linsolve))" for u0 in ([
1.0, 1.0],), prec in precs, linsolve in (nothing, KrylovJL_GMRES())
1.0, 1.0],), prec in precs, linsolve in (nothing, KrylovJL_GMRES(), \)
ad isa AutoZygote && continue
if prec === :Random
prec = (args...) -> (Diagonal(randn!(similar(u0))), nothing)
Expand Down Expand Up @@ -139,7 +139,7 @@ end
RadiusUpdateSchemes.NLsolve, RadiusUpdateSchemes.Hei, RadiusUpdateSchemes.Yuan,
RadiusUpdateSchemes.Fan, RadiusUpdateSchemes.Bastin]
u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)
linear_solvers = [nothing, LUFactorization(), KrylovJL_GMRES()]
linear_solvers = [nothing, LUFactorization(), KrylovJL_GMRES(), \]

@testset "[OOP] u0: $(typeof(u0)) radius_update_scheme: $(radius_update_scheme) linear_solver: $(linsolve)" for u0 in u0s,
radius_update_scheme in radius_update_schemes, linsolve in linear_solvers
Expand Down Expand Up @@ -471,7 +471,7 @@ end
precs = [NonlinearSolve.DEFAULT_PRECS, :Random]

@testset "[IIP] u0: $(typeof(u0)) precs: $(_nameof(prec)) linsolve: $(_nameof(linsolve))" for u0 in ([
1.0, 1.0],), prec in precs, linsolve in (nothing, KrylovJL_GMRES())
1.0, 1.0],), prec in precs, linsolve in (nothing, KrylovJL_GMRES(), \)
ad isa AutoZygote && continue
if prec === :Random
prec = (args...) -> (Diagonal(randn!(similar(u0))), nothing)
Expand Down

0 comments on commit c2791b9

Please sign in to comment.