Skip to content

Commit

Permalink
Merge pull request #53 from SciML/format
Browse files Browse the repository at this point in the history
format SciML Style
  • Loading branch information
ChrisRackauckas committed Jun 23, 2022
2 parents 7f97801 + 7e1ed77 commit 759b3b8
Show file tree
Hide file tree
Showing 14 changed files with 1,129 additions and 893 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "sciml"
42 changes: 42 additions & 0 deletions .github/workflows/FormatCheck.yml
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'
10 changes: 7 additions & 3 deletions src/StochasticDelayDiffEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ module StochasticDelayDiffEq
# using DifferentialEquations
using Reexport
@reexport using StochasticDiffEq
import StochasticDiffEq: stepsize_controller!, accept_step_controller, step_accept_controller!, step_reject_controller!, PIController
import StochasticDiffEq: stepsize_controller!, accept_step_controller,
step_accept_controller!, step_reject_controller!, PIController
# import StochasticDiffEq: calc_J, calc_J!, calc_tderivative!, calc_tderivative
using LinearAlgebra, StaticArrays
using UnPack, DataStructures
using Logging
using RecursiveArrayTools
using DiffEqBase: AbstractSDDEProblem, AbstractSDDEAlgorithm, AbstractRODESolution, AbstractRODEFunction, AbstractSDEIntegrator, AbstractSDDEIntegrator, DEIntegrator, DEAlgorithm, AbstractRODEAlgorithm, AbstractSDEAlgorithm
using DiffEqBase: AbstractSDDEProblem, AbstractSDDEAlgorithm, AbstractRODESolution,
AbstractRODEFunction, AbstractSDEIntegrator, AbstractSDDEIntegrator,
DEIntegrator, DEAlgorithm, AbstractRODEAlgorithm, AbstractSDEAlgorithm

import DelayDiffEq: constant_extrapolant!, constant_extrapolant, AbstractMethodOfStepsAlgorithm, iscomposite, MethodOfSteps
import DelayDiffEq: constant_extrapolant!, constant_extrapolant,
AbstractMethodOfStepsAlgorithm, iscomposite, MethodOfSteps
using DiffEqNoiseProcess

using DelayDiffEq: Discontinuity, HistoryFunction
Expand Down
100 changes: 55 additions & 45 deletions src/functionwrapper.jl
Original file line number Diff line number Diff line change
@@ -1,61 +1,71 @@
struct SDEDiffusionTermWrapper{iip,G,H}
g::G
h::H
struct SDEDiffusionTermWrapper{iip, G, H}
g::G
h::H
end
function SDEDiffusionTermWrapper(g::G,h::H) where {G,H}
SDEDiffusionTermWrapper{isinplace(g,5),G,H}(g,h)
function SDEDiffusionTermWrapper(g::G, h::H) where {G, H}
SDEDiffusionTermWrapper{isinplace(g, 5), G, H}(g, h)
end
(g::SDEDiffusionTermWrapper{true})(du, u, p, t) = g.g(du, u, g.h, p, t)
(g::SDEDiffusionTermWrapper{false})(u, p, t) = g.g(u, g.h, p, t)

struct SDEFunctionWrapper{iip,F,G,H,TMM,Ta,Tt,TJ,JVP,VJP,JP,SP,TW,TWt,TPJ,GG,S,TCV} <: DiffEqBase.AbstractRODEFunction{iip}
f::F
g::G
h::H
mass_matrix::TMM
analytic::Ta
tgrad::Tt
jac::TJ
jvp::JVP
vjp::VJP
jac_prototype::JP
sparsity::SP
Wfact::TW
Wfact_t::TWt
paramjac::TPJ
ggprime::GG
syms::S
colorvec::TCV
struct SDEFunctionWrapper{iip, F, G, H, TMM, Ta, Tt, TJ, JVP, VJP, JP, SP, TW, TWt, TPJ, GG,
S, TCV} <: DiffEqBase.AbstractRODEFunction{iip}
f::F
g::G
h::H
mass_matrix::TMM
analytic::Ta
tgrad::Tt
jac::TJ
jvp::JVP
vjp::VJP
jac_prototype::JP
sparsity::SP
Wfact::TW
Wfact_t::TWt
paramjac::TPJ
ggprime::GG
syms::S
colorvec::TCV
end


(f::SDEFunctionWrapper{true})(du, u, p, t) = f.f(du, u, f.h, p, t)
(f::SDEFunctionWrapper{false})(u, p, t) = f.f(u, f.h, p, t)

function wrap_functions_and_history(f::SDDEFunction, g, h)
gwh = SDEDiffusionTermWrapper{isinplace(g,5),typeof(g),typeof(h)}(g,h)
gwh = SDEDiffusionTermWrapper{isinplace(g, 5), typeof(g), typeof(h)}(g, h)

if f.jac === nothing
jac = nothing
else
if isinplace(f)
jac = let f_jac = f.jac, h = h
(J, u, p, t) -> f_jac(J, u, h, p, t)
end
if f.jac === nothing
jac = nothing
else
jac = let f_jac = f.jac, h = h
(u, p, t) -> f_jac(u, h, p, t)
end
if isinplace(f)
jac = let f_jac = f.jac, h = h
(J, u, p, t) -> f_jac(J, u, h, p, t)
end
else
jac = let f_jac = f.jac, h = h
(u, p, t) -> f_jac(u, h, p, t)
end
end
end
end

SDEFunctionWrapper{isinplace(f),typeof(f.f),typeof(gwh),typeof(h),typeof(f.mass_matrix),
typeof(f.analytic),typeof(f.tgrad),typeof(jac),typeof(f.jvp),
typeof(f.vjp),typeof(f.jac_prototype),typeof(f.sparsity),
typeof(f.Wfact),typeof(f.Wfact_t),typeof(f.paramjac),
typeof(f.ggprime),typeof(f.syms),typeof(f.colorvec)}(
f.f, gwh, h, f.mass_matrix, f.analytic, f.tgrad, jac,
f.jvp, f.vjp,
f.jac_prototype, f.sparsity, f.Wfact, f.Wfact_t,
f.paramjac, f.ggprime, f.syms, f.colorvec), gwh
SDEFunctionWrapper{isinplace(f), typeof(f.f), typeof(gwh), typeof(h),
typeof(f.mass_matrix),
typeof(f.analytic), typeof(f.tgrad), typeof(jac), typeof(f.jvp),
typeof(f.vjp), typeof(f.jac_prototype), typeof(f.sparsity),
typeof(f.Wfact), typeof(f.Wfact_t), typeof(f.paramjac),
typeof(f.ggprime), typeof(f.syms), typeof(f.colorvec)}(f.f, gwh, h,
f.mass_matrix,
f.analytic,
f.tgrad, jac,
f.jvp, f.vjp,
f.jac_prototype,
f.sparsity,
f.Wfact,
f.Wfact_t,
f.paramjac,
f.ggprime,
f.syms,
f.colorvec),
gwh
end
Loading

0 comments on commit 759b3b8

Please sign in to comment.