Skip to content

Commit 130fd30

Browse files
authored
[WIP] Removing SSubArray in favor of SizedArray (#25)
* some work towards removing SSubArray * improving types of returned values * update versions * update codecov CI * general maintenance * don't test ArrayInterface compat on older versions of Julia * more fixing * one more test
1 parent 2536759 commit 130fd30

File tree

14 files changed

+88
-813
lines changed

14 files changed

+88
-813
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ jobs:
2121
arch: x64
2222
- uses: julia-actions/julia-buildpkg@latest
2323
- uses: julia-actions/julia-runtest@latest
24-
- uses: codecov/codecov-action@v1
24+
- uses: julia-actions/julia-uploadcodecov@latest
2525
if: ${{ matrix.julia-version == '1.4' && matrix.os =='ubuntu-latest' }}
26+
env:
27+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "HybridArrays"
22
uuid = "1baab800-613f-4b0a-84e4-9cd3431bfbb9"
33
authors = ["Mateusz Baran <[email protected]>"]
4-
version = "0.3.9"
4+
version = "0.4.0"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -10,7 +10,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1010

1111
[compat]
1212
Requires = "1"
13-
StaticArrays = "=0.12.5"
13+
StaticArrays = "=1.0.0"
1414
julia = "1"
1515

1616
[extras]

src/HybridArrays.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ using Requires
3636
return false
3737
end
3838

39+
function all_dynamic_fixed_val(::Type{Tuple{}})
40+
return Val(:dynamic_fixed_true)
41+
end
42+
function all_dynamic_fixed_val(::Type{Size}) where Size<:Tuple
43+
return error("No indices given for size $Size")
44+
end
45+
3946
function all_dynamic_fixed_val(::Type{Size}, inds::StaticArrays.StaticIndexing{<:Union{Int, AbstractArray, Colon}}...) where Size<:Tuple
4047
return all_dynamic_fixed_val(Size, map(StaticArrays.unwrap, inds)...)
4148
end
@@ -140,7 +147,7 @@ HybridMatrix{S1,S2,T,M} = HybridArray{Tuple{S1,S2},T,2,M}
140147

141148
export HybridArray, HybridMatrix, HybridVector
142149

143-
include("ssubarray.jl")
150+
include("SSubArray.jl")
144151

145152
include("abstractarray.jl")
146153
include("arraymath.jl")

src/SSubArray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
const SSubArray{S,T,N,P,I,L} = SizedArray{S,T,N,N,SubArray{T,N,P,I,L}}

src/abstractarray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ Base.IndexStyle(a::HybridArray) = Base.IndexStyle(a.data)
4848
Base.IndexStyle(::Type{HA}) where {S,T,N,M,TData,HA<:HybridArray{S,T,N,M,TData}} = Base.IndexStyle(TData)
4949

5050
Base.vec(a::HybridArray) = vec(a.data)
51+
52+
StaticArrays.similar_type(::Type{<:SSubArray},::Type{T},s::Size{S}) where {S,T} = StaticArrays.default_similar_type(T,s,StaticArrays.length_val(s))

src/arraymath.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11

2-
function StaticArrays._one(s::Size, ::Type{SM}) where {Sel, N, SM <: HybridArrays.SSubArray{Tuple{N,N}, Sel}}
3-
return StaticArrays._one(s, SMatrix{N,N,Sel})
4-
end
5-
62
Base.one(A::HA) where {HA<:HybridMatrix} = HA(one(A.data))
73

8-
@inline function Base.zero(a::HA) where {S, Sel, HA <: SSubArray{S, Sel}}
9-
return StaticArrays.zeros(SArray{S, Sel})
4+
# This should make one(sized subarray) return SArray
5+
@inline function StaticArrays._construct_sametype(a::Type{<:SSubArray{Tuple{S,S},T}}, elements) where {S,T}
6+
return SMatrix{S,S,T}(elements)
7+
end
8+
@inline function StaticArrays._construct_sametype(a::SSubArray{Tuple{S,S},T}, elements) where {S,T}
9+
return SMatrix{S,S,T}(elements)
1010
end
1111

1212
Base.fill!(A::HybridArray, x) = fill!(A.data, x)
1313

14-
function Base.zero(a::HybridArray{S}) where {S}
14+
@inline function Base.zero(a::HybridArray{S}) where {S}
1515
return HybridArray{S}(zero(a.data))
1616
end
17+
18+
@inline function Base.zero(a::SSubArray{S,T}) where {S,T}
19+
return StaticArrays.zeros(SArray{S,T})
20+
end

src/convert.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Base.@propagate_inbounds (::Type{HybridArray{S,T}})(a::AbstractArray) where {S,T
1616
@inline convert(::Type{Array}, sa::HybridArray) = convert(Array, sa.data)
1717
@inline convert(::Type{Array{T}}, sa::HybridArray{S,T}) where {T,S} = convert(Array, sa.data)
1818
@inline convert(::Type{Array{T,N}}, sa::HybridArray{S,T,N}) where {T,S,N} = convert(Array, sa.data)
19+
@inline convert(::Type{Array{T,N} where T}, sa::HybridArray{S}) where {S,N} = convert(Array, sa.data)
1920

2021
function check_compatible_sizes(::Type{S}, a::NTuple{N,Int}) where {S,N}
2122
st = size_to_tuple(S)

src/indexing.jl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function _get_indices(i::Tuple, j::Int, i1::Type{Colon}, inds...)
3030
return (i[1], _get_indices(i[2:end], j+1, inds...)...)
3131
end
3232

33+
_totally_linear() = true
3334
_totally_linear(inds...) = false
3435
_totally_linear(inds::Type{Int}...) = true
3536
_totally_linear(inds::Type{Colon}...) = true
@@ -147,14 +148,10 @@ end
147148
if i == Int
148149
elseif i <: StaticVector
149150
push!(os, i.parameters[1].parameters[1])
150-
elseif i <: Base.Slice{<:StaticVector}
151-
push!(os, i.parameters[1].parameters[1].parameters[1])
152-
elseif i == Colon
151+
elseif i == Colon || i <: Base.Slice
153152
push!(os, s)
154153
elseif i <: SOneTo
155154
push!(os, i.parameters[1])
156-
elseif i <: Base.Slice{<:SOneTo}
157-
push!(os, i.parameters[1].parameters[1])
158155
elseif i <: Base.OneTo || i <: AbstractArray
159156
push!(os, Dynamic())
160157
else
@@ -282,3 +279,20 @@ end
282279
end
283280
end
284281
end
282+
283+
@inline function _view_hybrid(a::HybridArray{S}, ::Val{:dynamic_fixed_true}, inner_view, indices...) where {S}
284+
new_size = new_out_size(S, indices...)
285+
return SizedArray{new_size}(inner_view)
286+
end
287+
288+
@inline function _view_hybrid(a::HybridArray, ::Val{:dynamic_fixed_false}, inner_view, indices...)
289+
return inner_view
290+
end
291+
292+
@inline function Base.view(
293+
a::HybridArray{S},
294+
indices...,
295+
) where {S}
296+
inner_view = invoke(view, Tuple{AbstractArray, typeof(indices).parameters...}, a, indices...)
297+
return _view_hybrid(a, all_dynamic_fixed_val(S, indices...), inner_view, indices...)
298+
end

src/linalg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const HybridVecOrMatLike{T} = Union{HybridVector{<:Any, T}, HybridMatrixLike{T}}
5454
end
5555

5656
@inline hcat(a::HybridVecOrMatLike, b::HybridVecOrMatLike) = _hcat(Size(a), Size(b), a, b)
57-
@inline hcat(a::HybridVecOrMatLike, b::HybridVecOrMatLike, c::HybridVecOrMatLike...) = hcat(hcat(a,b), hcat(c...))
57+
@inline hcat(a::HybridVecOrMatLike, b::HybridVecOrMatLike, c::HybridVecOrMatLike...) = hcat(hcat(a,b), c...)
5858

5959
# used in _vcat and _hcat
6060
@inline +(::Dynamic, ::Dynamic) = Dynamic()

0 commit comments

Comments
 (0)