Skip to content

Commit 033ff58

Browse files
committed
Use weakdeps on Julia v1.9
1 parent f23f3a8 commit 033ff58

5 files changed

+56
-13
lines changed

Diff for: Project.toml

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
99
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
1010
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1111

12+
[weakdeps]
13+
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
14+
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
15+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
16+
17+
[extensions]
18+
StructArraysGPUArraysCoreExt = "GPUArraysCore"
19+
StructArraysStaticArraysCoreExt = "StaticArraysCore"
20+
StructArraysTablesExt = "Tables"
21+
1222
[compat]
1323
Adapt = "1, 2, 3"
1424
DataAPI = "1"
@@ -20,14 +30,17 @@ julia = "1.6"
2030

2131
[extras]
2232
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33+
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
2334
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
2435
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
2536
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
2637
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2738
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
39+
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
40+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
2841
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2942
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
3043
WeakRefStrings = "ea10d353-3f73-51f8-a26c-33c1cb351aa5"
3144

3245
[targets]
33-
test = ["Test", "JLArrays", "StaticArrays", "OffsetArrays", "PooledArrays", "TypedTables", "WeakRefStrings", "Documenter", "SparseArrays"]
46+
test = ["Test", "JLArrays", "StaticArrays", "OffsetArrays", "PooledArrays", "TypedTables", "WeakRefStrings", "Documenter", "SparseArrays", "GPUArraysCore", "StaticArraysCore", "Tables"]

Diff for: ext/StructArraysGPUArraysCoreExt.jl

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module StructArraysGPUArraysCoreExt
2+
3+
using StructArrays
4+
using StructArrays: map_params, array_types
5+
6+
using Base: tail
7+
8+
import GPUArraysCore
9+
10+
# for GPU broadcast
11+
import GPUArraysCore
12+
function GPUArraysCore.backend(::Type{T}) where {T<:StructArray}
13+
backends = map_params(GPUArraysCore.backend, array_types(T))
14+
backend, others = backends[1], tail(backends)
15+
isconsistent = mapfoldl(isequal(backend), &, others; init=true)
16+
isconsistent || throw(ArgumentError("all component arrays must have the same GPU backend"))
17+
return backend
18+
end
19+
StructArrays.always_struct_broadcast(::GPUArraysCore.AbstractGPUArrayStyle) = true
20+
21+
end # module

Diff for: src/staticarrays_support.jl renamed to ext/StructArraysStaticArraysCoreExt.jl

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
module StructArraysStaticArraysCoreExt
2+
3+
using StructArrays
4+
using StructArrays: StructArrayStyle, createinstance, replace_structarray, isnonemptystructtype
5+
6+
using Base.Broadcast: Broadcasted
7+
18
using StaticArraysCore: StaticArray, FieldArray, tuple_prod
29

310
"""
@@ -40,7 +47,7 @@ Broadcast._axes(bc::Broadcasted{<:StructStaticArrayStyle}, ::Nothing) = axes(rep
4047

4148
# StaticArrayStyle has no similar defined.
4249
# Overload `Base.copy` instead.
43-
@inline function try_struct_copy(bc::Broadcasted{StaticArrayStyle{M}}) where {M}
50+
@inline function StructArrays.try_struct_copy(bc::Broadcasted{StaticArrayStyle{M}}) where {M}
4451
sa = copy(bc)
4552
ET = eltype(sa)
4653
isnonemptystructtype(ET) || return sa
@@ -66,3 +73,5 @@ end
6673
return map(Base.Fix2(getfield, i), x)
6774
end
6875
end
76+
77+
end # module

Diff for: src/tables.jl renamed to ext/StructArraysTablesExt.jl

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
module StructArraysTablesExt
2+
3+
using StructArrays
4+
using StructArrays: components, hasfields, foreachfield, staticschema
5+
16
import Tables
27

38
Tables.isrowtable(::Type{<:StructArray}) = true
@@ -38,3 +43,5 @@ for (f, g) in zip((:append!, :prepend!), (:push!, :pushfirst!))
3843
end
3944
end
4045
end
46+
47+
end # module

Diff for: src/StructArrays.jl

+4-11
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ include("utils.jl")
1212
include("collect.jl")
1313
include("sort.jl")
1414
include("lazy.jl")
15-
include("tables.jl")
16-
include("staticarrays_support.jl")
1715

1816
# Implement refarray and refvalue to deal with pooled arrays and weakrefstrings effectively
1917
import DataAPI: refarray, refvalue
@@ -29,15 +27,10 @@ end
2927
import Adapt
3028
Adapt.adapt_structure(to, s::StructArray) = replace_storage(x->Adapt.adapt(to, x), s)
3129

32-
# for GPU broadcast
33-
import GPUArraysCore
34-
function GPUArraysCore.backend(::Type{T}) where {T<:StructArray}
35-
backends = map_params(GPUArraysCore.backend, array_types(T))
36-
backend, others = backends[1], tail(backends)
37-
isconsistent = mapfoldl(isequal(backend), &, others; init=true)
38-
isconsistent || throw(ArgumentError("all component arrays must have the same GPU backend"))
39-
return backend
30+
@static if !isdefined(Base, :get_extension)
31+
include("../ext/StructArraysGPUArraysCoreExt.jl")
32+
include("../ext/StructArraysTablesExt.jl")
33+
include("../ext/StructArraysStaticArraysCoreExt.jl")
4034
end
41-
always_struct_broadcast(::GPUArraysCore.AbstractGPUArrayStyle) = true
4235

4336
end # module

0 commit comments

Comments
 (0)