Skip to content

Commit

Permalink
Merge pull request #358 from SciML/ap/direct_ldiv
Browse files Browse the repository at this point in the history
Allow linsolve to be \
  • Loading branch information
ChrisRackauckas authored Jan 30, 2024
2 parents e989b72 + d840c17 commit 7e0685a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 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
3 changes: 2 additions & 1 deletion src/internal/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ use this functionality unless it can't be avoided (like in [`LevenbergMarquardt`

# Extension Algorithm Helpers
function __test_termination_condition(termination_condition, alg)
termination_condition !== AbsNormTerminationMode && termination_condition !== nothing &&
!(termination_condition isa AbsNormTerminationMode) &&
termination_condition !== nothing &&
error("`$(alg)` does not support termination conditions!")
end

Expand Down
16 changes: 6 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,5 @@ 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
@inline __needs_square_A(::typeof(\), ::Number) = false # Ambiguity Fix
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
@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

2 comments on commit 7e0685a

@avik-pal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/99928

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.5.1 -m "<description of version>" 7e0685a31e36a802885290729e59ae64e42f6d30
git push origin v3.5.1

Please sign in to comment.