-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from SciML/format
Format SciML Style
- Loading branch information
Showing
14 changed files
with
816 additions
and
727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
style = "sciml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: format-check | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
- 'release-' | ||
tags: '*' | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
julia-version: [1] | ||
julia-arch: [x86] | ||
os: [ubuntu-latest] | ||
steps: | ||
- uses: julia-actions/setup-julia@latest | ||
with: | ||
version: ${{ matrix.julia-version }} | ||
|
||
- uses: actions/checkout@v1 | ||
- name: Install JuliaFormatter and format | ||
# This will use the latest version by default but you can set the version like so: | ||
# | ||
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))' | ||
run: | | ||
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))' | ||
julia -e 'using JuliaFormatter; format(".", verbose=true)' | ||
- name: Format check | ||
run: | | ||
julia -e ' | ||
out = Cmd(`git diff --name-only`) |> read |> String | ||
if out == "" | ||
exit(0) | ||
else | ||
@error "Some files have not been formatted !!!" | ||
write(stdout, out) | ||
exit(1) | ||
end' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
# Put in a separate page so it can be used by SciMLDocs.jl | ||
|
||
pages=[ | ||
pages = [ | ||
"Home" => "index.md", | ||
"Tutorials" => Any[ | ||
"tutorials/nonlinear.md", | ||
"tutorials/iterator_interface.md" | ||
], | ||
"Basics" => Any[ | ||
"basics/NonlinearProblem.md", | ||
"basics/NonlinearFunctions.md", | ||
"basics/FAQ.md" | ||
], | ||
"Solvers" => Any[ | ||
"solvers/NonlinearSystemSolvers.md", | ||
"solvers/BracketingSolvers.md" | ||
] | ||
] | ||
"Tutorials" => Any["tutorials/nonlinear.md", | ||
"tutorials/iterator_interface.md"], | ||
"Basics" => Any["basics/NonlinearProblem.md", | ||
"basics/NonlinearFunctions.md", | ||
"basics/FAQ.md"], | ||
"Solvers" => Any["solvers/NonlinearSystemSolvers.md", | ||
"solvers/BracketingSolvers.md"], | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,116 @@ | ||
struct Bisection <: AbstractBracketingAlgorithm | ||
exact_left::Bool | ||
exact_right::Bool | ||
exact_left::Bool | ||
exact_right::Bool | ||
end | ||
|
||
function Bisection(;exact_left=false, exact_right=false) | ||
Bisection(exact_left, exact_right) | ||
function Bisection(; exact_left = false, exact_right = false) | ||
Bisection(exact_left, exact_right) | ||
end | ||
|
||
struct BisectionCache{uType} | ||
state::Int | ||
left::uType | ||
right::uType | ||
state::Int | ||
left::uType | ||
right::uType | ||
end | ||
|
||
function alg_cache(alg::Bisection, left, right, p, ::Val{true}) | ||
BisectionCache(0, left, right) | ||
BisectionCache(0, left, right) | ||
end | ||
|
||
function alg_cache(alg::Bisection, left, right, p, ::Val{false}) | ||
BisectionCache(0, left, right) | ||
BisectionCache(0, left, right) | ||
end | ||
|
||
function perform_step(solver::BracketingImmutableSolver, alg::Bisection, cache) | ||
@unpack f, p, left, right, fl, fr, cache = solver | ||
|
||
if cache.state == 0 | ||
fzero = zero(fl) | ||
fl * fr > fzero && error("Bracket became non-containing in between iterations. This could mean that " | ||
* "input function crosses the x axis multiple times. Bisection is not the right method to solve this.") | ||
|
||
mid = (left + right) / 2 | ||
|
||
if left == mid || right == mid | ||
@set! solver.force_stop = true | ||
@set! solver.retcode = FLOATING_POINT_LIMIT | ||
return solver | ||
end | ||
|
||
fm = f(mid, p) | ||
|
||
if iszero(fm) | ||
if alg.exact_left | ||
@set! cache.state = 1 | ||
@set! cache.right = mid | ||
@set! cache.left = mid | ||
@set! solver.cache = cache | ||
elseif alg.exact_right | ||
@set! solver.left = prevfloat_tdir(mid, left, right) | ||
solver = sync_residuals!(solver) | ||
@set! cache.state = 2 | ||
@set! cache.left = mid | ||
@set! solver.cache = cache | ||
else | ||
@set! solver.left = prevfloat_tdir(mid, left, right) | ||
@set! solver.right = nextfloat_tdir(mid, left, right) | ||
solver = sync_residuals!(solver) | ||
@set! solver.force_stop = true | ||
return solver | ||
end | ||
else | ||
if sign(fm) == sign(fl) | ||
@set! solver.left = mid | ||
@set! solver.fl = fm | ||
else | ||
@set! solver.right = mid | ||
@set! solver.fr = fm | ||
end | ||
end | ||
elseif cache.state == 1 | ||
mid = (left + cache.right) / 2 | ||
|
||
if cache.right == mid || left == mid | ||
if alg.exact_right | ||
@set! cache.state = 2 | ||
@set! solver.cache = cache | ||
return solver | ||
else | ||
@set! solver.right = nextfloat_tdir(mid, left, right) | ||
solver = sync_residuals!(solver) | ||
@set! solver.force_stop = true | ||
return solver | ||
end | ||
end | ||
|
||
fm = f(mid, p) | ||
@unpack f, p, left, right, fl, fr, cache = solver | ||
|
||
if iszero(fm) | ||
@set! cache.right = mid | ||
@set! solver.cache = cache | ||
else | ||
@set! solver.left = mid | ||
@set! solver.fl = fm | ||
end | ||
else | ||
mid = (cache.left + right) / 2 | ||
|
||
if right == mid || cache.left == mid | ||
@set! solver.force_stop = true | ||
return solver | ||
end | ||
|
||
fm = f(mid, p) | ||
if cache.state == 0 | ||
fzero = zero(fl) | ||
fl * fr > fzero && | ||
error("Bracket became non-containing in between iterations. This could mean that " | ||
* | ||
"input function crosses the x axis multiple times. Bisection is not the right method to solve this.") | ||
|
||
mid = (left + right) / 2 | ||
|
||
if iszero(fm) | ||
@set! cache.left = mid | ||
@set! solver.cache = cache | ||
if left == mid || right == mid | ||
@set! solver.force_stop = true | ||
@set! solver.retcode = FLOATING_POINT_LIMIT | ||
return solver | ||
end | ||
|
||
fm = f(mid, p) | ||
|
||
if iszero(fm) | ||
if alg.exact_left | ||
@set! cache.state = 1 | ||
@set! cache.right = mid | ||
@set! cache.left = mid | ||
@set! solver.cache = cache | ||
elseif alg.exact_right | ||
@set! solver.left = prevfloat_tdir(mid, left, right) | ||
solver = sync_residuals!(solver) | ||
@set! cache.state = 2 | ||
@set! cache.left = mid | ||
@set! solver.cache = cache | ||
else | ||
@set! solver.left = prevfloat_tdir(mid, left, right) | ||
@set! solver.right = nextfloat_tdir(mid, left, right) | ||
solver = sync_residuals!(solver) | ||
@set! solver.force_stop = true | ||
return solver | ||
end | ||
else | ||
if sign(fm) == sign(fl) | ||
@set! solver.left = mid | ||
@set! solver.fl = fm | ||
else | ||
@set! solver.right = mid | ||
@set! solver.fr = fm | ||
end | ||
end | ||
elseif cache.state == 1 | ||
mid = (left + cache.right) / 2 | ||
|
||
if cache.right == mid || left == mid | ||
if alg.exact_right | ||
@set! cache.state = 2 | ||
@set! solver.cache = cache | ||
return solver | ||
else | ||
@set! solver.right = nextfloat_tdir(mid, left, right) | ||
solver = sync_residuals!(solver) | ||
@set! solver.force_stop = true | ||
return solver | ||
end | ||
end | ||
|
||
fm = f(mid, p) | ||
|
||
if iszero(fm) | ||
@set! cache.right = mid | ||
@set! solver.cache = cache | ||
else | ||
@set! solver.left = mid | ||
@set! solver.fl = fm | ||
end | ||
else | ||
@set! solver.right = mid | ||
@set! solver.fr = fm | ||
mid = (cache.left + right) / 2 | ||
|
||
if right == mid || cache.left == mid | ||
@set! solver.force_stop = true | ||
return solver | ||
end | ||
|
||
fm = f(mid, p) | ||
|
||
if iszero(fm) | ||
@set! cache.left = mid | ||
@set! solver.cache = cache | ||
else | ||
@set! solver.right = mid | ||
@set! solver.fr = fm | ||
end | ||
end | ||
end | ||
solver | ||
solver | ||
end |
Oops, something went wrong.