Skip to content

Commit 0f185ef

Browse files
Merge pull request #92 from SciML/format
format SciML Style
2 parents fcead75 + 63006a4 commit 0f185ef

File tree

12 files changed

+398
-360
lines changed

12 files changed

+398
-360
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "sciml"

.github/workflows/FormatCheck.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: format-check
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'release-'
8+
tags: '*'
9+
pull_request:
10+
11+
jobs:
12+
build:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
julia-version: [1]
17+
julia-arch: [x86]
18+
os: [ubuntu-latest]
19+
steps:
20+
- uses: julia-actions/setup-julia@latest
21+
with:
22+
version: ${{ matrix.julia-version }}
23+
24+
- uses: actions/checkout@v1
25+
- name: Install JuliaFormatter and format
26+
# This will use the latest version by default but you can set the version like so:
27+
#
28+
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
29+
run: |
30+
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
31+
julia -e 'using JuliaFormatter; format(".", verbose=true)'
32+
- name: Format check
33+
run: |
34+
julia -e '
35+
out = Cmd(`git diff --name-only`) |> read |> String
36+
if out == ""
37+
exit(0)
38+
else
39+
@error "Some files have not been formatted !!!"
40+
write(stdout, out)
41+
exit(1)
42+
end'

docs/make.jl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ using Documenter, ParameterizedFunctions
22

33
include("pages.jl")
44

5-
makedocs(
6-
sitename="ParameterizedFunctions.jl",
7-
authors="Chris Rackauckas",
8-
modules=[ParameterizedFunctions],
9-
clean=true,doctest=false,
10-
format = Documenter.HTML(analytics = "UA-90474609-3",
11-
assets = ["assets/favicon.ico"],
12-
canonical="https://parameterizedfunctions.sciml.ai/stable/"),
13-
pages=pages
14-
)
5+
makedocs(sitename = "ParameterizedFunctions.jl",
6+
authors = "Chris Rackauckas",
7+
modules = [ParameterizedFunctions],
8+
clean = true, doctest = false,
9+
format = Documenter.HTML(analytics = "UA-90474609-3",
10+
assets = ["assets/favicon.ico"],
11+
canonical = "https://parameterizedfunctions.sciml.ai/stable/"),
12+
pages = pages)
1513

16-
deploydocs(
17-
repo = "github.com/SciML/ParameterizedFunctions.jl.git";
18-
push_preview = true
19-
)
14+
deploydocs(repo = "github.com/SciML/ParameterizedFunctions.jl.git";
15+
push_preview = true)

docs/pages.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Put in a separate page so it can be used by SciMLDocs.jl
22

3-
pages=[
3+
pages = [
44
"Home" => "index.md",
55
"ode_def.md",
6-
]
6+
]

src/ParameterizedFunctions.jl

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,25 @@ $(DocStringExtensions.README)
66
module ParameterizedFunctions
77

88
using DocStringExtensions
9-
using DataStructures, DiffEqBase, Latexify
10-
using Reexport
11-
@reexport using ModelingToolkit
12-
using ModelingToolkit: Sym, FnType, tosymbol
9+
using DataStructures, DiffEqBase, Latexify
10+
using Reexport
11+
@reexport using ModelingToolkit
12+
using ModelingToolkit: Sym, FnType, tosymbol
1313

14+
import LinearAlgebra
1415

15-
import LinearAlgebra
16+
import Base: getindex
1617

17-
import Base: getindex
18+
include("ode_def_opts.jl")
19+
include("ode_findrep.jl")
20+
include("utils.jl")
21+
include("dict_build.jl")
22+
include("macros.jl")
23+
include("latexify.jl")
1824

19-
include("ode_def_opts.jl")
20-
include("ode_findrep.jl")
21-
include("utils.jl")
22-
include("dict_build.jl")
23-
include("macros.jl")
24-
include("latexify.jl")
25-
26-
export @ode_def,ode_def_opts,@ode_def_bare, @ode_def_all
25+
export @ode_def, ode_def_opts, @ode_def_bare, @ode_def_all
2726
end # module
2827

29-
30-
31-
3228
##### Extra
3329

3430
# Jacobian Factorization

src/dict_build.jl

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
function build_indvar_dict(ex,depvar)
2-
indvar_dict = OrderedDict{Symbol,Int}()
3-
cur_sym = 0
4-
for i in 2:2:length(ex.args) #Every odd line is line number
5-
arg = ex.args[i].args[1] #Get the first thing, should be dsomething
6-
firstarg = Symbol(first(string(arg))) # Check for d
7-
if firstarg == :d
8-
nodarg = Symbol(join(Base.Iterators.drop(string(arg), 1)))
9-
if nodarg == depvar
10-
warn("$depvar is fixed as the independent variable but is also used as a dependent variable. Results my be incorrect.")
11-
end
12-
if !haskey(indvar_dict,nodarg)
13-
cur_sym += 1
14-
indvar_dict[nodarg] = cur_sym
15-
else
16-
error("The derivative term for $nodarg is repeated. This is not allowed.")
17-
end
1+
function build_indvar_dict(ex, depvar)
2+
indvar_dict = OrderedDict{Symbol, Int}()
3+
cur_sym = 0
4+
for i in 2:2:length(ex.args) #Every odd line is line number
5+
arg = ex.args[i].args[1] #Get the first thing, should be dsomething
6+
firstarg = Symbol(first(string(arg))) # Check for d
7+
if firstarg == :d
8+
nodarg = Symbol(join(Base.Iterators.drop(string(arg), 1)))
9+
if nodarg == depvar
10+
warn("$depvar is fixed as the independent variable but is also used as a dependent variable. Results my be incorrect.")
11+
end
12+
if !haskey(indvar_dict, nodarg)
13+
cur_sym += 1
14+
indvar_dict[nodarg] = cur_sym
15+
else
16+
error("The derivative term for $nodarg is repeated. This is not allowed.")
17+
end
18+
end
1819
end
19-
end
20-
syms = indvar_dict.keys
21-
indvar_dict,syms
20+
syms = indvar_dict.keys
21+
indvar_dict, syms
2222
end
2323

2424
function build_param_list(params)
25-
param_list = Vector{Symbol}();
26-
for i in 1:length(params)
27-
if typeof(params[i]) <: Symbol
28-
push!(param_list,params[i])
29-
elseif params[i].head == :call || params[i].head == :(=)
30-
warn("p=>val and p=val are deprecated. Simply list the parameters. See the DifferentialEquations.jl documentation for more information on the syntax change.")
25+
param_list = Vector{Symbol}()
26+
for i in 1:length(params)
27+
if typeof(params[i]) <: Symbol
28+
push!(param_list, params[i])
29+
elseif params[i].head == :call || params[i].head == :(=)
30+
warn("p=>val and p=val are deprecated. Simply list the parameters. See the DifferentialEquations.jl documentation for more information on the syntax change.")
31+
end
3132
end
32-
end
33-
param_dict
33+
param_dict
3434
end

src/latexify.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
@latexrecipe function f(func::DiffEqBase.AbstractParameterizedFunction)
2-
return latexify(func.sys)
3-
end
1+
@latexrecipe function f(func::DiffEqBase.AbstractParameterizedFunction)
2+
return latexify(func.sys)
3+
end

src/macros.jl

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,17 @@ end a b c d
3232
extra definitions (Jacobian, parameter Jacobian, etc.) defined through the MTK
3333
symbolic tools.
3434
"""
35-
macro ode_def(name,ex,params...)
36-
opts = Dict{Symbol,Bool}(
37-
:build_tgrad => true,
38-
:build_jac => true,
39-
:build_expjac => false,
40-
:build_invjac => false,
41-
:build_invW => false,
42-
:build_hes => false,
43-
:build_invhes => false,
44-
:build_dpfuncs => true)
45-
name isa Expr ? ode_def_opts(gensym(),opts,__module__,name,ex,params...) :
46-
ode_def_opts(name,opts,__module__,ex,params...)
35+
macro ode_def(name, ex, params...)
36+
opts = Dict{Symbol, Bool}(:build_tgrad => true,
37+
:build_jac => true,
38+
:build_expjac => false,
39+
:build_invjac => false,
40+
:build_invW => false,
41+
:build_hes => false,
42+
:build_invhes => false,
43+
:build_dpfuncs => true)
44+
name isa Expr ? ode_def_opts(gensym(), opts, __module__, name, ex, params...) :
45+
ode_def_opts(name, opts, __module__, ex, params...)
4746
end
4847

4948
"""
@@ -56,18 +55,17 @@ end parameters :: ODEFunction
5655
Like `@ode_def` but the `opts` options are set so that no symbolic functions are generated.
5756
See the `@ode_def` docstring for more details.
5857
"""
59-
macro ode_def_bare(name,ex,params...)
60-
opts = Dict{Symbol,Bool}(
61-
:build_tgrad => false,
62-
:build_jac => false,
63-
:build_expjac => false,
64-
:build_invjac => false,
65-
:build_invW => false,
66-
:build_hes => false,
67-
:build_invhes => false,
68-
:build_dpfuncs => false)
69-
name isa Expr ? ode_def_opts(gensym(),opts,__module__,name,ex,params...) :
70-
ode_def_opts(name,opts,__module__,ex,params...)
58+
macro ode_def_bare(name, ex, params...)
59+
opts = Dict{Symbol, Bool}(:build_tgrad => false,
60+
:build_jac => false,
61+
:build_expjac => false,
62+
:build_invjac => false,
63+
:build_invW => false,
64+
:build_hes => false,
65+
:build_invhes => false,
66+
:build_dpfuncs => false)
67+
name isa Expr ? ode_def_opts(gensym(), opts, __module__, name, ex, params...) :
68+
ode_def_opts(name, opts, __module__, ex, params...)
7169
end
7270

7371
"""
@@ -80,16 +78,15 @@ end parameters :: ODEFunction
8078
Like `@ode_def` but the `opts` options are set so that all possible symbolic functions are generated.
8179
See the `@ode_def` docstring for more details.
8280
"""
83-
macro ode_def_all(name,ex,params...)
84-
opts = Dict{Symbol,Bool}(
85-
:build_tgrad => true,
86-
:build_jac => true,
87-
:build_expjac => false,
88-
:build_invjac => false,
89-
:build_invW => true,
90-
:build_hes => false,
91-
:build_invhes => false,
92-
:build_dpfuncs => true)
93-
name isa Expr ? ode_def_opts(gensym(),opts,__module__,name,ex,params...) :
94-
ode_def_opts(name,opts,__module__,ex,params...)
81+
macro ode_def_all(name, ex, params...)
82+
opts = Dict{Symbol, Bool}(:build_tgrad => true,
83+
:build_jac => true,
84+
:build_expjac => false,
85+
:build_invjac => false,
86+
:build_invW => true,
87+
:build_hes => false,
88+
:build_invhes => false,
89+
:build_dpfuncs => true)
90+
name isa Expr ? ode_def_opts(gensym(), opts, __module__, name, ex, params...) :
91+
ode_def_opts(name, opts, __module__, ex, params...)
9592
end

0 commit comments

Comments
 (0)