Skip to content

Commit 5f3c0ad

Browse files
Merge pull request #149 from SciML/format2
Format SciML Style
2 parents 3c5e8cb + 3541ed0 commit 5f3c0ad

19 files changed

+959
-806
lines changed

.JuliaFormatter.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "sciml"

.github/workflows/FormatCheck.yml

+42
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

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
using LinearSolve
22
using Documenter
33

4-
DocMeta.setdocmeta!(LinearSolve, :DocTestSetup, :(using LinearSolve); recursive=true)
4+
DocMeta.setdocmeta!(LinearSolve, :DocTestSetup, :(using LinearSolve); recursive = true)
55

66
include("pages.jl")
77

8-
makedocs(
9-
sitename="LinearSolve.jl",
10-
authors="Chris Rackauckas",
11-
modules=[LinearSolve,LinearSolve.SciMLBase],
12-
clean=true,doctest=false,
13-
format = Documenter.HTML(analytics = "UA-90474609-3",
14-
assets = ["assets/favicon.ico"],
15-
canonical="https://linearsolve.sciml.ai/stable/"),
16-
pages=pages
17-
)
8+
makedocs(sitename = "LinearSolve.jl",
9+
authors = "Chris Rackauckas",
10+
modules = [LinearSolve, LinearSolve.SciMLBase],
11+
clean = true, doctest = false,
12+
format = Documenter.HTML(analytics = "UA-90474609-3",
13+
assets = ["assets/favicon.ico"],
14+
canonical = "https://linearsolve.sciml.ai/stable/"),
15+
pages = pages)
1816

1917
deploydocs(;
20-
repo="github.com/SciML/LinearSolve.jl",
21-
devbranch="main",
22-
)
18+
repo = "github.com/SciML/LinearSolve.jl",
19+
devbranch = "main")

docs/pages.jl

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
# Put in a separate page so it can be used by SciMLDocs.jl
22

3-
pages=[
3+
pages = [
44
"Home" => "index.md",
5-
"Tutorials" => Any[
6-
"tutorials/linear.md"
7-
"tutorials/caching_interface.md"
8-
],
9-
"Basics" => Any[
10-
"basics/LinearProblem.md",
11-
"basics/common_solver_opts.md",
12-
"basics/CachingAPI.md",
13-
"basics/Preconditioners.md",
14-
"basics/FAQ.md"
15-
],
16-
"Solvers" => Any[
17-
"solvers/solvers.md"
18-
],
19-
"Advanced" => Any[
20-
"advanced/developing.md"
21-
"advanced/custom.md"
22-
]
23-
]
5+
"Tutorials" => Any["tutorials/linear.md"
6+
"tutorials/caching_interface.md"],
7+
"Basics" => Any["basics/LinearProblem.md",
8+
"basics/common_solver_opts.md",
9+
"basics/CachingAPI.md",
10+
"basics/Preconditioners.md",
11+
"basics/FAQ.md"],
12+
"Solvers" => Any["solvers/solvers.md"],
13+
"Advanced" => Any["advanced/developing.md"
14+
"advanced/custom.md"],
15+
]

lib/LinearSolveCUDA/src/LinearSolveCUDA.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ using CUDA, LinearAlgebra, LinearSolve, SciMLBase
44

55
struct CudaOffloadFactorization <: LinearSolve.AbstractFactorization end
66

7-
function SciMLBase.solve(cache::LinearSolve.LinearCache, alg::CudaOffloadFactorization; kwargs...)
7+
function SciMLBase.solve(cache::LinearSolve.LinearCache, alg::CudaOffloadFactorization;
8+
kwargs...)
89
if cache.isfresh
910
fact = LinearSolve.do_factorization(alg, CUDA.CuArray(cache.A), cache.b, cache.u)
1011
cache = LinearSolve.set_cacheval(cache, fact)
@@ -16,7 +17,7 @@ function SciMLBase.solve(cache::LinearSolve.LinearCache, alg::CudaOffloadFactori
1617
end
1718

1819
function LinearSolve.do_factorization(alg::CudaOffloadFactorization, A, b, u)
19-
A isa Union{AbstractMatrix,SciMLBase.AbstractDiffEqOperator} ||
20+
A isa Union{AbstractMatrix, SciMLBase.AbstractDiffEqOperator} ||
2021
error("LU is not defined for $(typeof(A))")
2122

2223
if A isa SciMLBase.AbstractDiffEqOperator
@@ -28,4 +29,4 @@ end
2829

2930
export CudaOffloadFactorization
3031

31-
end
32+
end

lib/LinearSolveCUDA/test/runtests.jl

+27-17
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,50 @@ using LinearSolve, LinearSolveCUDA, LinearAlgebra, SparseArrays
22
using Test
33

44
n = 8
5-
A = Matrix(I,n,n)
5+
A = Matrix(I, n, n)
66
b = ones(n)
7-
A1 = A/1; b1 = rand(n); x1 = zero(b)
8-
A2 = A/2; b2 = rand(n); x2 = zero(b)
7+
A1 = A / 1;
8+
b1 = rand(n);
9+
x1 = zero(b);
10+
A2 = A / 2;
11+
b2 = rand(n);
12+
x2 = zero(b);
913

10-
prob1 = LinearProblem(A1, b1; u0=x1)
11-
prob2 = LinearProblem(A2, b2; u0=x2)
14+
prob1 = LinearProblem(A1, b1; u0 = x1)
15+
prob2 = LinearProblem(A2, b2; u0 = x2)
1216

13-
cache_kwargs = (;verbose=true, abstol=1e-8, reltol=1e-8, maxiter=30,)
17+
cache_kwargs = (; verbose = true, abstol = 1e-8, reltol = 1e-8, maxiter = 30)
1418

1519
function test_interface(alg, prob1, prob2)
16-
A1 = prob1.A; b1 = prob1.b; x1 = prob1.u0
17-
A2 = prob2.A; b2 = prob2.b; x2 = prob2.u0
20+
A1 = prob1.A
21+
b1 = prob1.b
22+
x1 = prob1.u0
23+
A2 = prob2.A
24+
b2 = prob2.b
25+
x2 = prob2.u0
1826

1927
y = solve(prob1, alg; cache_kwargs...)
20-
@test A1 * y b1
28+
@test A1 * y b1
2129

22-
cache = SciMLBase.init(prob1,alg; cache_kwargs...) # initialize cache
30+
cache = SciMLBase.init(prob1, alg; cache_kwargs...) # initialize cache
2331
y = solve(cache)
24-
@test A1 * y b1
32+
@test A1 * y b1
2533

26-
cache = LinearSolve.set_A(cache,copy(A2))
34+
cache = LinearSolve.set_A(cache, copy(A2))
2735
y = solve(cache)
28-
@test A2 * y b1
36+
@test A2 * y b1
2937

30-
cache = LinearSolve.set_b(cache,b2)
38+
cache = LinearSolve.set_b(cache, b2)
3139
y = solve(cache)
32-
@test A2 * y b2
40+
@test A2 * y b2
3341

3442
return
3543
end
3644

3745
test_interface(CudaOffloadFactorization(), prob1, prob2)
3846

39-
A1 = prob1.A; b1 = prob1.b; x1 = prob1.u0
47+
A1 = prob1.A;
48+
b1 = prob1.b;
49+
x1 = prob1.u0;
4050
y = solve(prob1)
41-
@test A1 * y b1
51+
@test A1 * y b1

lib/LinearSolvePardiso/src/LinearSolvePardiso.jl

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@ using Pardiso, LinearSolve, SciMLBase
44
using UnPack
55

66
Base.@kwdef struct PardisoJL <: LinearSolve.SciMLLinearSolveAlgorithm
7-
nprocs::Union{Int,Nothing} = nothing
8-
solver_type::Union{Int,Pardiso.Solver,Nothing} = nothing
9-
matrix_type::Union{Int,Pardiso.MatrixType,Nothing} = nothing
10-
iparm::Union{Vector{Tuple{Int,Int}},Nothing} = nothing
11-
dparm::Union{Vector{Tuple{Int,Int}},Nothing} = nothing
7+
nprocs::Union{Int, Nothing} = nothing
8+
solver_type::Union{Int, Pardiso.Solver, Nothing} = nothing
9+
matrix_type::Union{Int, Pardiso.MatrixType, Nothing} = nothing
10+
iparm::Union{Vector{Tuple{Int, Int}}, Nothing} = nothing
11+
dparm::Union{Vector{Tuple{Int, Int}}, Nothing} = nothing
1212
end
1313

14-
MKLPardisoFactorize(; kwargs...) = PardisoJL(; solver_type=0, kwargs...)
15-
MKLPardisoIterate(; kwargs...) = PardisoJL(; solver_type=1, kwargs...)
14+
MKLPardisoFactorize(; kwargs...) = PardisoJL(; solver_type = 0, kwargs...)
15+
MKLPardisoIterate(; kwargs...) = PardisoJL(; solver_type = 1, kwargs...)
1616
LinearSolve.needs_concrete_A(alg::PardisoJL) = true
1717

1818
# TODO schur complement functionality
1919

20-
function LinearSolve.init_cacheval(alg::PardisoJL, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose)
20+
function LinearSolve.init_cacheval(alg::PardisoJL, A, b, u, Pl, Pr, maxiters, abstol,
21+
reltol, verbose)
2122
@unpack nprocs, solver_type, matrix_type, iparm, dparm = alg
2223
A = convert(AbstractMatrix, A)
2324

24-
solver =
25-
if Pardiso.PARDISO_LOADED[]
26-
solver = Pardiso.PardisoSolver()
27-
solver_type !== nothing && Pardiso.set_solver!(solver, solver_type)
25+
solver = if Pardiso.PARDISO_LOADED[]
26+
solver = Pardiso.PardisoSolver()
27+
solver_type !== nothing && Pardiso.set_solver!(solver, solver_type)
2828

29-
solver
30-
else
31-
solver = Pardiso.MKLPardisoSolver()
32-
nprocs !== nothing && Pardiso.set_nprocs!(solver, nprocs)
29+
solver
30+
else
31+
solver = Pardiso.MKLPardisoSolver()
32+
nprocs !== nothing && Pardiso.set_nprocs!(solver, nprocs)
3333

34-
solver
35-
end
34+
solver
35+
end
3636

3737
Pardiso.pardisoinit(solver) # default initialization
3838

@@ -113,4 +113,4 @@ end
113113

114114
export PardisoJL, MKLPardisoFactorize, MKLPardisoIterate
115115

116-
end
116+
end

lib/LinearSolvePardiso/test/runtests.jl

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using LinearSolve, LinearSolvePardiso, SparseArrays, Random
22

33
A1 = sparse([1.0 0 -2 3
4-
0 5 1 2
5-
-2 1 4 -7
6-
3 2 -7 5])
4+
0 5 1 2
5+
-2 1 4 -7
6+
3 2 -7 5])
77
b1 = rand(4)
88
prob1 = LinearProblem(A1, b1)
99

@@ -13,16 +13,13 @@ e = ones(n)
1313
e2 = ones(n - 1)
1414
A2 = spdiagm(-1 => im * e2, 0 => lambda * e, 1 => -im * e2)
1515
b2 = rand(n) + im * zeros(n)
16-
cache_kwargs = (; verbose=true, abstol=1e-8, reltol=1e-8, maxiter=30)
16+
cache_kwargs = (; verbose = true, abstol = 1e-8, reltol = 1e-8, maxiter = 30)
1717

1818
prob2 = LinearProblem(A2, b2)
1919

20-
for alg in (
21-
PardisoJL(),
22-
MKLPardisoFactorize(),
23-
MKLPardisoIterate(),
24-
)
25-
20+
for alg in (PardisoJL(),
21+
MKLPardisoFactorize(),
22+
MKLPardisoIterate())
2623
u = solve(prob1, alg; cache_kwargs...).u
2724
@test A1 * u b1
2825

@@ -55,4 +52,4 @@ sol33 = solve(linsolve)
5552

5653
@test sol11.u sol31.u
5754
@test sol12.u sol32.u
58-
@test sol13.u sol33.u
55+
@test sol13.u sol33.u

src/LinearSolve.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using RecursiveFactorization
55
using Base: cache_dependencies, Bool
66
import Base: eltype, adjoint, inv
77
using LinearAlgebra
8-
using IterativeSolvers:Identity
8+
using IterativeSolvers: Identity
99
using SparseArrays
1010
using SciMLBase: AbstractDiffEqOperator, AbstractLinearAlgorithm
1111
using Setfield

0 commit comments

Comments
 (0)