Skip to content

Commit

Permalink
Move out the @bb macro into a separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Nov 24, 2023
1 parent e4d4960 commit d4936bc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 172 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MaybeInplace = "bb5d69b7-63fc-4a16-80bd-7e42200c7bdb"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
Expand Down
10 changes: 2 additions & 8 deletions src/SimpleNonlinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,25 @@ import PrecompileTools: @compile_workload, @setup_workload, @recompile_invalidat

@recompile_invalidations begin
using ADTypes,
ArrayInterface, ConcreteStructs, DiffEqBase, Reexport, LinearAlgebra,
SciMLBase
ArrayInterface, ConcreteStructs, DiffEqBase, Reexport, LinearAlgebra, SciMLBase

import DiffEqBase: AbstractNonlinearTerminationMode,
AbstractSafeNonlinearTerminationMode, AbstractSafeBestNonlinearTerminationMode,
NonlinearSafeTerminationReturnCode, get_termination_mode
using FiniteDiff, ForwardDiff
import ForwardDiff: Dual
import MaybeInplace: @bb, setindex_trait, CanSetindex, CannotSetindex
import SciMLBase: AbstractNonlinearAlgorithm, build_solution, isinplace
import StaticArraysCore: StaticArray, SVector, SMatrix, SArray, MArray
end

@reexport using ADTypes, SciMLBase

# const NNlibExtLoaded = Ref{Bool}(false)

abstract type AbstractSimpleNonlinearSolveAlgorithm <: AbstractNonlinearAlgorithm end
abstract type AbstractBracketingAlgorithm <: AbstractSimpleNonlinearSolveAlgorithm end
abstract type AbstractNewtonAlgorithm <: AbstractSimpleNonlinearSolveAlgorithm end

include("utils.jl")
include("rewrite_inplace.jl")

# Nonlinear Solvera
include("nlsolve/raphson.jl")
Expand All @@ -50,7 +47,6 @@ include("bracketing/itp.jl")
## Default algorithm

# Set the default bracketing method to ITP

function SciMLBase.solve(prob::IntervalNonlinearProblem; kwargs...)
return solve(prob, ITP(); kwargs...)
end
Expand All @@ -60,8 +56,6 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Nothing,
return solve(prob, ITP(), args...; kwargs...)
end

# import PrecompileTools

@setup_workload begin
for T in (Float32, Float64)
# prob_no_brack = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2))
Expand Down
2 changes: 1 addition & 1 deletion src/bracketing/ridder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Ridder, args...;

sol, i, left, right, fl, fr = __bisection(left, right, fl, fr, f; abstol,
maxiters = maxiters - i, prob, alg)
sol !== nothing && return sol
sol !== nothing && return sol

return SciMLBase.build_solution(prob, alg, left, fl; retcode = ReturnCode.MaxIters,
left, right)
Expand Down
8 changes: 6 additions & 2 deletions src/nlsolve/klement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleKlement, args...;
end

@bb copyto!(δx, fprev)
δx = __ldiv!!(F_, δx)
if setindex_trait(δx) === CanSetindex()
ldiv!(F_, δx)
else
δx = F_ \ δx
end
@bb @. x = xo - δx
fx = __eval_f(prob, fx, x)

Expand All @@ -74,7 +78,7 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleKlement, args...;
@bb δx² = J × vec(δx)
@bb @. δf = (δf - δx²) / d

_vδf, _vδx = vec(δf), vec(δx)
_vδf, _vδx = _vec(δf), _vec(δx)
@bb J_cache = _vδf × transpose(_vδx)
@bb @. J_cache *= J
@bb J_cache2 = J_cache × J
Expand Down
161 changes: 0 additions & 161 deletions src/rewrite_inplace.jl

This file was deleted.

0 comments on commit d4936bc

Please sign in to comment.