Skip to content

Commit fc5d289

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

File tree

6 files changed

+64
-21
lines changed

6 files changed

+64
-21
lines changed

Project.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
99
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
1010
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1111

12+
[weakdeps]
13+
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
14+
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
15+
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
16+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
17+
18+
[extensions]
19+
StructArraysDataAPIExt = "DataAPI"
20+
StructArraysGPUArraysCoreExt = "GPUArraysCore"
21+
StructArraysStaticArraysCoreExt = "StaticArraysCore"
22+
StructArraysTablesExt = "Tables"
23+
1224
[compat]
1325
Adapt = "1, 2, 3"
1426
DataAPI = "1"

ext/StructArraysDataAPIExt.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module StructArraysDataAPIExt
2+
3+
using StructArrays
4+
using StructArrays: Tup
5+
6+
# Implement refarray and refvalue to deal with pooled arrays and weakrefstrings effectively
7+
import DataAPI: refarray, refvalue
8+
using DataAPI: defaultarray
9+
10+
refarray(s::StructArray) = StructArray(map(refarray, components(s)))
11+
12+
function refvalue(s::StructArray{T}, v::Tup) where {T}
13+
createinstance(T, map(refvalue, components(s), v)...)
14+
end
15+
16+
end # module

ext/StructArraysGPUArraysCoreExt.jl

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

src/staticarrays_support.jl renamed to ext/StructArraysStaticArraysCoreExt.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
module StructArraysStaticArraysCoreExt
2+
3+
using StructArrays
4+
using StructArrays: StructArrayStyle
5+
6+
using Base.Broadcast: Broadcasted
7+
18
using StaticArraysCore: StaticArray, FieldArray, tuple_prod
29

310
"""
@@ -66,3 +73,5 @@ end
6673
return map(Base.Fix2(getfield, i), x)
6774
end
6875
end
76+
77+
end # module

src/tables.jl renamed to ext/StructArraysTablesExt.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
module StructArraysTablesExt
2+
3+
using StructArrays
14
import Tables
25

36
Tables.isrowtable(::Type{<:StructArray}) = true
@@ -38,3 +41,5 @@ for (f, g) in zip((:append!, :prepend!), (:push!, :pushfirst!))
3841
end
3942
end
4043
end
44+
45+
end # module

src/StructArrays.jl

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,16 @@ 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

18-
# Implement refarray and refvalue to deal with pooled arrays and weakrefstrings effectively
19-
import DataAPI: refarray, refvalue
20-
using DataAPI: defaultarray
21-
22-
refarray(s::StructArray) = StructArray(map(refarray, components(s)))
23-
24-
function refvalue(s::StructArray{T}, v::Tup) where {T}
25-
createinstance(T, map(refvalue, components(s), v)...)
16+
@static if !isdefined(Base, :get_extension)
17+
include("../ext/StructArraysDataAPIExt.jl")
18+
include("../ext/StructArraysGPUArraysCoreExt.jl")
19+
include("../ext/StructArraysTablesExt.jl")
20+
include("../ext/StructArraysStaticArraysCoreExt.jl")
2621
end
2722

2823
# Use Adapt allows for automatic conversion of CPU to GPU StructArrays
2924
import Adapt
3025
Adapt.adapt_structure(to, s::StructArray) = replace_storage(x->Adapt.adapt(to, x), s)
3126

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
40-
end
41-
always_struct_broadcast(::GPUArraysCore.AbstractGPUArrayStyle) = true
42-
4327
end # module

0 commit comments

Comments
 (0)