Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
style = "sciml"
format_markdown = true
format_markdown = true
format_docstrings = true
14 changes: 7 additions & 7 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
include("pages.jl")

makedocs(sitename = "LabelledArrays.jl",
authors = "Chris Rackauckas",
modules = [LabelledArrays],
clean = true, doctest = false, linkcheck = true,
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/LabelledArrays/stable/"),
pages = pages)
authors = "Chris Rackauckas",
modules = [LabelledArrays],
clean = true, doctest = false, linkcheck = true,
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/LabelledArrays/stable/"),
pages = pages)

deploydocs(repo = "github.com/SciML/LabelledArrays.jl.git";
push_preview = true)
push_preview = true)
2 changes: 1 addition & 1 deletion docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pages = [
"SLArrays" => "SLArrays.md",
"LArrays" => "LArrays.md",
"Relation to NamedTuples" => "NamedTuples_relation.md",
"Note_labelled_slices.md",
"Note_labelled_slices.md"
]
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ file and the
[project]($link_project)
file.
""")
```
```
6 changes: 3 additions & 3 deletions src/LabelledArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end

import Base: eltype, length, ndims, size, axes, eachindex, stride, strides
MacroTools.@forward PrintWrapper.x eltype, length, ndims, size, axes, eachindex, stride,
strides
strides
Base.getindex(A::PrintWrapper, idxs...) = A.f(A.x, A.x[idxs...], idxs)

function lazypair(A, x, idxs)
Expand Down Expand Up @@ -72,8 +72,8 @@ function ArrayInterface.undefmatrix(x::LArray{T, N, D, Syms}) where {T, N, D, Sy
end

function PreallocationTools.get_tmp(dc::PreallocationTools.DiffCache,
u::LArray{T, N, D, Syms}) where {T <: ForwardDiff.Dual,
N, D, Syms}
u::LArray{T, N, D, Syms}) where {T <: ForwardDiff.Dual,
N, D, Syms}
nelem = div(sizeof(T), sizeof(eltype(dc.dual_du))) * length(dc.du)
if nelem > length(dc.dual_du)
PreallocationTools.enlargedualcache!(dc, nelem)
Expand Down
34 changes: 18 additions & 16 deletions src/larray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Base.@propagate_inbounds function Base.getindex(x::LArray, s::AbstractArray{Symb
end

function Base.similar(x::LArray{T, K, D, Syms}, ::Type{S},
dims::NTuple{N, Int}) where {T, K, D, Syms, S, N}
dims::NTuple{N, Int}) where {T, K, D, Syms, S, N}
tmp = similar(x.__x, S, dims)
LArray{S, N, typeof(tmp), Syms}(tmp)
end
Expand All @@ -144,15 +144,15 @@ Base.convert(::Type{T}, x) where {T <: LArray} = T(x)
Base.convert(::Type{T}, x::T) where {T <: LArray} = x
Base.convert(::Type{<:Array}, x::LArray) = convert(Array, getfield(x, :__x))
function Base.convert(::Type{AbstractArray{T, N}},
x::LArray{S, N, <:Any, Syms}) where {T, S, N, Syms}
x::LArray{S, N, <:Any, Syms}) where {T, S, N, Syms}
LArray{Syms}(convert(AbstractArray{T, N}, getfield(x, :__x)))
end
Base.convert(::Type{AbstractArray{T, N}}, x::LArray{T, N}) where {T, N} = x

function ArrayInterface.restructure(x::LArray{T, N, D, Syms},
y::LArray{T2, N2, D2, Syms}) where {T, N, D, T2, N2,
D2,
Syms}
y::LArray{T2, N2, D2, Syms}) where {T, N, D, T2, N2,
D2,
Syms}
reshape(y, size(x)...)
end

Expand All @@ -163,7 +163,7 @@ struct LAStyle{T, N, L} <: Broadcast.AbstractArrayStyle{N} end
LAStyle{T, N, L}(x::Val{i}) where {T, N, L, i} = LAStyle{T, N, L}()
Base.BroadcastStyle(::Type{LArray{T, N, D, L}}) where {T, N, D, L} = LAStyle{T, N, L}()
function Base.BroadcastStyle(::LabelledArrays.LAStyle{T, N, L},
::LabelledArrays.LAStyle{E, N, L}) where {T, E, N, L}
::LabelledArrays.LAStyle{E, N, L}) where {T, E, N, L}
LAStyle{promote_type(T, E), N, L}()
end

Expand All @@ -177,7 +177,7 @@ end
end
end
function Base.similar(bc::Broadcast.Broadcasted{LAStyle{T, N, L}},
::Type{ElType}) where {T, N, L, ElType}
::Type{ElType}) where {T, N, L, ElType}
tmp = similar(Array{ElType}, axes(bc))
if axes(bc) != labels2axes(Val(L))
return tmp
Expand Down Expand Up @@ -368,23 +368,25 @@ For example:
B2 = SLArray(B; c=30 )
"""
function SLArray(v1::Union{SLArray{S, T, N, L, Syms}, LArray{T, N, D, Syms}};
kwargs...) where {S, T, N, L, Syms, D}
kwargs...) where {S, T, N, L, Syms, D}
t2 = merge(convert(NamedTuple, v1), values(kwargs))
SLArray{S}(t2)
end

function Base.vcat(x::LArray, y::LArray)
LArray{(LabelledArrays.symnames(typeof(x))..., LabelledArrays.symnames(typeof(y))...)}(vcat(x.__x,
y.__x))
LArray{(LabelledArrays.symnames(typeof(x))..., LabelledArrays.symnames(typeof(y))...)}(vcat(
x.__x,
y.__x))
end

Base.elsize(::Type{<:LArray{T}}) where {T} = sizeof(T)

function RecursiveArrayTools.recursive_unitless_eltype(a::Type{LArray{T, N, D, Syms}}) where {
T,
N,
D,
Syms
}
function RecursiveArrayTools.recursive_unitless_eltype(a::Type{LArray{
T, N, D, Syms}}) where {
T,
N,
D,
Syms
}
LArray{typeof(one(T)), N, D, Syms}
end
22 changes: 11 additions & 11 deletions src/slarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ end
#####################################
## SLArray to named tuple
function Base.convert(::Type{NamedTuple},
x::SLArray{S, T, N, L, Syms}) where {S, T, N, L, Syms}
x::SLArray{S, T, N, L, Syms}) where {S, T, N, L, Syms}
tup = NTuple{length(Syms), T}(x.__x)
NamedTuple{Syms, typeof(tup)}(tup)
end
Base.keys(x::SLArray{S, T, N, L, Syms}) where {S, T, N, L, Syms} = Syms

function StaticArrays.similar_type(::Type{SLArray{S, T, N, L, Syms}}, T2,
::Size{S}) where {S, T, N, L, Syms}
::Size{S}) where {S, T, N, L, Syms}
SLArray{S, T2, N, L, Syms}
end
function RecursiveArrayTools.recursive_unitless_eltype(a::Type{T}) where {T <: SLArray}
Expand Down Expand Up @@ -157,8 +157,8 @@ Base.@propagate_inbounds Base.getindex(x::SLArray, i::Int) = getfield(x, :__x)[i
@inline Base.Tuple(x::SLArray) = Tuple(x.__x)

function StaticArrays.similar_type(::Type{SLArray{S, T, N, L, Syms}}, ::Type{NewElType},
::Size{NewSize}) where {S, T, N, L, Syms, NewElType,
NewSize}
::Size{NewSize}) where {S, T, N, L, Syms, NewElType,
NewSize}
n = prod(NewSize)
if n == L
SLArray{Tuple{NewSize...}, NewElType, length(NewSize), L, Syms}
Expand All @@ -168,7 +168,7 @@ function StaticArrays.similar_type(::Type{SLArray{S, T, N, L, Syms}}, ::Type{New
end

function Base.similar(::Type{SLArray{S, T, N, L, Syms}}, ::Type{NewElType},
::Size{NewSize}) where {S, T, N, L, Syms, NewElType, NewSize}
::Size{NewSize}) where {S, T, N, L, Syms, NewElType, NewSize}
n = prod(NewSize)
if n == L
tmp = Array{NewElType}(undef, NewSize)
Expand All @@ -188,9 +188,9 @@ Base.@propagate_inbounds function Base.getindex(x::SLArray, s::Symbol)
end
Base.@propagate_inbounds Base.getindex(x::SLArray, s::Val) = __getindex(x, s)
Base.@propagate_inbounds function Base.getindex(x::SLArray,
inds::AbstractArray{I, 1}) where {
I <:
Integer}
inds::AbstractArray{I, 1}) where {
I <:
Integer}
getindex(x.__x, inds)
end
Base.@propagate_inbounds function Base.getindex(x::SLArray, inds::StaticVector{<:Any, Int})
Expand All @@ -203,7 +203,7 @@ Base.@propagate_inbounds function Base.getindex(x::SLArray, s::AbstractArray{Sym
end

function Base.vcat(x1::SLArray{S1, T, 1, L1, Syms1},
x2::SLArray{S2, T, 1, L2, Syms2}) where {S1, S2, T, L1, L2, Syms1, Syms2}
x2::SLArray{S2, T, 1, L2, Syms2}) where {S1, S2, T, L1, L2, Syms1, Syms2}
__x = vcat(x1.__x, x2.__x)
SLArray{StaticArrays.size_tuple(Size(__x)), (Syms1..., Syms2...)}(__x)
end
Expand Down Expand Up @@ -335,7 +335,7 @@ function Base.:\(A::StaticArrays.LU, b::SLArray{S, T, N, L, Syms}) where {S, T,
end

function Base.reshape(x::SLArray{S, T, N, L, Syms},
ax::Tuple{SOneTo, Vararg{SOneTo}}) where {S <: Tuple, T, N, L, Syms,
SOneTo <: SOneTo}
ax::Tuple{SOneTo, Vararg{SOneTo}}) where {S <: Tuple, T, N, L, Syms,
SOneTo <: SOneTo}
SLArray{S, T, N, L, Syms}(reshape(x.__x, ax))
end
2 changes: 1 addition & 1 deletion test/larrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ using LabelledArrays, Test, InteractiveUtils
@test_throws ErrorException x.z

# Ref #93, #154
@test_broken @LVector [1, 2, 3] (:a, :b, :c)
@test_broken @LVector [1, 2, 3] (:a, :b, :c)
end

@testset "Alternate array backends" begin
Expand Down
16 changes: 12 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ using InteractiveUtils
using ChainRulesTestUtils

@time begin
@time @testset "SLArrays" begin include("slarrays.jl") end
@time @testset "LArrays" begin include("larrays.jl") end
@time @testset "DiffEq" begin include("diffeq.jl") end
@time @testset "ChainRules" begin include("chainrules.jl") end
@time @testset "SLArrays" begin
include("slarrays.jl")
end
@time @testset "LArrays" begin
include("larrays.jl")
end
@time @testset "DiffEq" begin
include("diffeq.jl")
end
@time @testset "ChainRules" begin
include("chainrules.jl")
end
end