Skip to content

Commit 005e22e

Browse files
committed
Migrate non-Static.jl dependent methods back
This gets a good chunk of the methods that can be made independent of Static.jl but were in StaticArrayInterface.jl. - is_splat_index - known_length: the followning are necessary to get known_length to work - known_size - known_first - known_last - known_step
1 parent 2be78bd commit 005e22e

13 files changed

+460
-11
lines changed

Project.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ ArrayInterfaceBandedMatricesExt = "BandedMatrices"
1919
ArrayInterfaceBlockBandedMatricesExt = "BlockBandedMatrices"
2020
ArrayInterfaceCUDAExt = "CUDA"
2121
ArrayInterfaceGPUArraysCoreExt = "GPUArraysCore"
22+
ArrayInterfaceOffsetArraysExt = "OffsetArrays"
2223
ArrayInterfaceStaticArraysCoreExt = "StaticArraysCore"
24+
ArrayInterfaceStaticArraysExt = "StaticArrays"
25+
ArrayInterfaceStaticExt = "Static"
2326
ArrayInterfaceTrackerExt = "Tracker"
2427

2528
[extras]
@@ -30,21 +33,26 @@ CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
3033
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
3134
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3235
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
36+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
3337
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
3438
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
3539
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
40+
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
3641
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
3742
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
3843
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
3944
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4045

4146
[targets]
42-
test = ["SafeTestsets", "Pkg", "Test", "Aqua", "Random", "SparseArrays", "SuiteSparse", "BandedMatrices", "BlockBandedMatrices", "GPUArraysCore", "StaticArrays", "StaticArraysCore", "Tracker"]
47+
test = ["SafeTestsets", "Pkg", "Test", "Aqua", "Random", "SparseArrays", "SuiteSparse", "BandedMatrices", "BlockBandedMatrices", "GPUArraysCore", "OffsetArrays", "StaticArrays", "StaticArraysCore", "Static", "Tracker"]
4348

4449
[weakdeps]
4550
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
4651
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
4752
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
53+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
54+
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
55+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
4856
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
4957
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
5058
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"

docs/src/indexing.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ArrayInterface.can_change_size
1414
ArrayInterface.can_setindex
1515
ArrayInterface.fast_scalar_indexing
1616
ArrayInterface.ismutable
17+
ArrayInterface.is_splat_index
1718
ArrayInterface.ndims_index
1819
ArrayInterface.ndims_shape
1920
ArrayInterface.defines_strides
@@ -22,6 +23,11 @@ ArrayInterface.ensures_sorted
2223
ArrayInterface.indices_do_not_alias
2324
ArrayInterface.instances_do_not_alias
2425
ArrayInterface.device
26+
ArrayInterface.known_first
27+
ArrayInterface.known_step
28+
ArrayInterface.known_last
29+
ArrayInterface.known_size
30+
ArrayInterface.known_length
2531
```
2632

2733
## Allowed Indexing Functions
@@ -46,4 +52,4 @@ and index translations.
4652
ArrayInterface.ArrayIndex
4753
ArrayInterface.GetIndex
4854
ArrayInterface.SetIndex!
49-
```
55+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module ArrayInterfaceOffsetArraysExt
2+
3+
if isdefined(Base, :get_extension)
4+
using ArrayInterface
5+
using OffsetArrays
6+
else
7+
using ..ArrayInterface
8+
using ..OffsetArrays
9+
end
10+
11+
ArrayInterface.parent_type(@nospecialize T::Type{<:OffsetArrays.IdOffsetRange}) = fieldtype(T, :parent)
12+
ArrayInterface.parent_type(@nospecialize T::Type{<:OffsetArray}) = fieldtype(T, :parent)
13+
14+
function ArrayInterface.known_size(@nospecialize T::Type{<:OffsetArrays.IdOffsetRange})
15+
ArrayInterface.known_size(ArrayInterface.parent_type(T))
16+
end
17+
function ArrayInterface.known_size(@nospecialize T::Type{<:OffsetArray})
18+
ArrayInterface.known_size(ArrayInterface.parent_type(T))
19+
end
20+
21+
end

ext/ArrayInterfaceStaticArraysCoreExt.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,13 @@ end
3232

3333
ArrayInterface.restructure(x::StaticArraysCore.SArray{S}, y) where {S} = StaticArraysCore.SArray{S}(y)
3434

35+
function ArrayInterface.known_size(::Type{<:StaticArraysCore.StaticArray{S}}) where {S}
36+
@isdefined(S) ? tuple(S.parameters...) : ntuple(_-> nothing, ndims(T))
37+
end
38+
39+
function ArrayInterface.known_length(T::Type{<:StaticArraysCore.StaticArray})
40+
sz = ArrayInterface.known_size(T)
41+
isa(sz, Tuple{Vararg{Nothing}}) ? nothing : prod(sz)
42+
end
43+
3544
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module ArrayInterfaceStaticArraysExt
2+
3+
if isdefined(Base, :get_extension)
4+
import ArrayInterface
5+
import StaticArrays
6+
else
7+
import ..ArrayInterface
8+
import ..StaticArrays
9+
end
10+
11+
ArrayInterface.known_first(@nospecialize T::Type{<:StaticArrays.SOneTo}) = 1
12+
ArrayInterface.known_last(::Type{StaticArrays.SOneTo{N}}) where {N} = @isdefined(N) ? N::Int : nothing
13+
14+
function ArrayInterface.known_first(::Type{<:StaticArrays.SUnitRange{S}}) where {S}
15+
@isdefined(S) ? S::Int : nothing
16+
end
17+
function ArrayInterface.known_size(::Type{<:StaticArrays.SUnitRange{<:Any, L}}) where {L}
18+
@isdefined(L) ? (L::Int,) : (nothing,)
19+
end
20+
function ArrayInterface.known_last(::Type{<:StaticArrays.SUnitRange{S, L}}) where {S, L}
21+
start = @isdefined(S) ? S::Int : nothing
22+
len = @isdefined(L) ? L::Int : nothing
23+
(start === nothing || len === nothing) ? nothing : (start + len - 1)
24+
end
25+
26+
end

ext/ArrayInterfaceStaticExt.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module ArrayInterfaceStaticExt
2+
3+
if isdefined(Base, :get_extension)
4+
import ArrayInterface
5+
import Static
6+
else
7+
import ..ArrayInterface
8+
import ..Static
9+
end
10+
11+
ArrayInterface.known_first(::Type{<:Static.OptionallyStaticUnitRange{Static.StaticInt{F}}}) where {F} = F::Int
12+
ArrayInterface.known_first(::Type{<:Static.OptionallyStaticStepRange{Static.StaticInt{F}}}) where {F} = F::Int
13+
14+
ArrayInterface.known_step(::Type{<:Static.OptionallyStaticStepRange{<:Any,Static.StaticInt{S}}}) where {S} = S::Int
15+
16+
ArrayInterface.known_last(::Type{<:Static.OptionallyStaticUnitRange{<:Any,Static.StaticInt{L}}}) where {L} = L::Int
17+
ArrayInterface.known_last(::Type{<:Static.OptionallyStaticStepRange{<:Any,<:Any,Static.StaticInt{L}}}) where {L} = L::Int
18+
19+
end

0 commit comments

Comments
 (0)