Skip to content

Commit d2ca535

Browse files
Merge pull request #121 from SciML/format2
Use SciML Style
2 parents 167e4d0 + a6ec7b4 commit d2ca535

13 files changed

Lines changed: 469 additions & 392 deletions

File tree

.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, LabelledArrays
22

33
include("pages.jl")
44

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

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

docs/pages.jl

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

3-
pages=[
3+
pages = [
44
"Home" => "index.md",
55
"Example: Nice DiffEq Syntax Without A DSL" => "Example_dsl.md",
66
"SLArrays" => "SLArrays.md",
77
"LArrays" => "LArrays.md",
88
"Relation to NamedTuples" => "NamedTuples_relation.md",
9-
"Note_labelled_slices.md"
9+
"Note_labelled_slices.md",
1010
]

src/LabelledArrays.jl

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,62 @@ include("larray.jl")
77
include("chainrules.jl")
88

99
# Common
10-
@generated function __getindex(x::Union{LArray,SLArray},::Val{s}) where s
10+
@generated function __getindex(x::Union{LArray, SLArray}, ::Val{s}) where {s}
1111
syms = symnames(x)
12-
idx = syms isa NamedTuple ? syms[s] : findfirst(y->y==s,syms)
12+
idx = syms isa NamedTuple ? syms[s] : findfirst(y -> y == s, syms)
1313
if idx === nothing
1414
:(error("type $(typeof(x)) has no field $(s)"))
1515
elseif idx isa Tuple
16-
:(Base.@_propagate_inbounds_meta; view(getfield(x,:__x), $idx...))
16+
:(Base.@_propagate_inbounds_meta; view(getfield(x, :__x), $idx...))
1717
else
18-
:(Base.@_propagate_inbounds_meta; @views getfield(x,:__x)[$idx])
18+
:(Base.@_propagate_inbounds_meta; @views getfield(x, :__x)[$idx])
1919
end
2020
end
2121

2222
using MacroTools
2323

24-
struct PrintWrapper{T,N,F,X<:AbstractArray{T,N}} <: AbstractArray{T,N}
24+
struct PrintWrapper{T, N, F, X <: AbstractArray{T, N}} <: AbstractArray{T, N}
2525
f::F
2626
x::X
2727
end
2828

2929
import Base: eltype, length, ndims, size, axes, eachindex, stride, strides
30-
MacroTools.@forward PrintWrapper.x eltype, length, ndims, size, axes, eachindex, stride, strides
30+
MacroTools.@forward PrintWrapper.x eltype, length, ndims, size, axes, eachindex, stride,
31+
strides
3132
Base.getindex(A::PrintWrapper, idxs...) = A.f(A.x, A.x[idxs...], idxs)
3233

3334
function lazypair(A, x, idxs)
3435
syms = symnames(typeof(A))
3536
II = LinearIndices(A)
36-
key = eltype(syms) <: Symbol ? syms[II[idxs...]] : findfirst(syms) do sym
37+
key = eltype(syms) <: Symbol ? syms[II[idxs...]] :
38+
findfirst(syms) do sym
3739
ii = idxs isa Tuple ? II[idxs...] : II[idxs]
3840
sym isa Tuple ? ii in II[sym...] : ii in II[sym]
3941
end
4042
key => x
4143
end
4244

43-
Base.show(io::IO, ::MIME"text/plain", x::Union{LArray,SLArray}) = show(io, x)
44-
function Base.show(io::IO, x::Union{LArray,SLArray})
45+
Base.show(io::IO, ::MIME"text/plain", x::Union{LArray, SLArray}) = show(io, x)
46+
function Base.show(io::IO, x::Union{LArray, SLArray})
4547
syms = symnames(typeof(x))
4648
n = length(syms)
4749
pwrapper = PrintWrapper(lazypair, x)
48-
if io isa IOContext && get(io, :limit, false) && displaysize(io) isa Tuple{Integer, Integer}
49-
io = IOContext(io, :limit => true, :displaysize => cld.(2 .*displaysize(io), 3))
50+
if io isa IOContext && get(io, :limit, false) &&
51+
displaysize(io) isa Tuple{Integer, Integer}
52+
io = IOContext(io, :limit => true, :displaysize => cld.(2 .* displaysize(io), 3))
5053
end
5154
println(io, summary(x), ':')
5255
Base.print_array(io, pwrapper)
5356
end
5457

55-
Base.NamedTuple(x::Union{LArray,SLArray}) = NamedTuple{symnames(typeof(x))}(x.__x)
58+
Base.NamedTuple(x::Union{LArray, SLArray}) = NamedTuple{symnames(typeof(x))}(x.__x)
5659
@inline Base.reshape(a::SLArray, s::Size) = StaticArrays.similar_type(a, s)(Tuple(a))
5760

58-
function ArrayInterface.ismutable(::Type{<:LArray{T,N,Syms}}) where {T,N,Syms}
61+
function ArrayInterface.ismutable(::Type{<:LArray{T, N, Syms}}) where {T, N, Syms}
5962
ArrayInterface.ismutable(T)
6063
end
6164
ArrayInterface.can_setindex(::Type{<:SLArray}) = false
62-
65+
6366
export SLArray, LArray, SLVector, LVector, @SLVector, @LArray, @LVector, @SLArray
6467

6568
export @SLSliced, @LSliced

src/chainrules.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function unwrap_maybe(x::ChainRulesCore.Thunk)
88
return ChainRulesCore.@thunk(unwrap_maybe(ChainRulesCore.unthunk(x)))
99
end
1010

11-
function ChainRulesCore.rrule(::typeof(getproperty), A::Union{SLArray,LArray}, s::Symbol)
11+
function ChainRulesCore.rrule(::typeof(getproperty), A::Union{SLArray, LArray}, s::Symbol)
1212
function getproperty_LArray_adjoint(d)
1313
# Hopefully this reference to `A` is optimized away.
1414
Δ = similar(A) .= 0
@@ -25,9 +25,9 @@ function ChainRulesCore.rrule(::Type{LArray{S}}, x::AbstractArray) where {S}
2525
return LArray{S}(x), LArray_adjoint
2626
end
2727

28-
function ChainRulesCore.rrule(::Type{SLArray{Size,S}}, x::AbstractArray) where {Size,S}
28+
function ChainRulesCore.rrule(::Type{SLArray{Size, S}}, x::AbstractArray) where {Size, S}
2929
# This rule covers constructors of the form `SLArray{(2, ), (:a, :b)}(x)`
3030
# which, amongst other places, is also used in the `@LArray` macro.
3131
SLArray_adjoint(Δ) = ChainRulesCore.NoTangent(), unwrap_maybe(Δ)
32-
return SLArray{Size,S}(x), SLArray_adjoint
32+
return SLArray{Size, S}(x), SLArray_adjoint
3333
end

0 commit comments

Comments
 (0)