Skip to content

Commit b1aa851

Browse files
authored
fix: circular dep due to Functors (#280)
* fix: circular dep due to Functors * fix: circular dep due to Adapt
1 parent 7adf959 commit b1aa851

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

Project.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
name = "ComponentArrays"
22
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
33
authors = ["Jonnie Diegelman <[email protected]>"]
4-
version = "0.15.18"
4+
version = "0.15.19"
55

66
[deps]
7+
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
78
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
89
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
10+
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
911
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1012
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
1113
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1214
StaticArrayInterface = "0d7ed370-da01-4f52-bd93-41d350b8b718"
1315
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
1416

1517
[weakdeps]
16-
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
17-
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
1818
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
1919
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
2020
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
@@ -24,8 +24,6 @@ Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
2424
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2525

2626
[extensions]
27-
ComponentArraysAdaptExt = "Adapt"
28-
ComponentArraysConstructionBaseExt = "ConstructionBase"
2927
ComponentArraysGPUArraysExt = "GPUArrays"
3028
ComponentArraysOptimisersExt = "Optimisers"
3129
ComponentArraysRecursiveArrayToolsExt = "RecursiveArrayTools"

ext/ComponentArraysAdaptExt.jl

Lines changed: 0 additions & 13 deletions
This file was deleted.

ext/ComponentArraysConstructionBaseExt.jl

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/ComponentArrays.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ module ComponentArrays
22

33
import ChainRulesCore
44
import StaticArrayInterface, ArrayInterface, Functors
5+
import ConstructionBase
6+
import Adapt
57

68
using LinearAlgebra
79
using StaticArraysCore: StaticArray, SArray, SVector, SMatrix
810

911
const FlatIdx = Union{Integer, CartesianIndex, CartesianIndices, AbstractArray{<:Integer}}
1012
const FlatOrColonIdx = Union{FlatIdx, Colon}
1113

12-
1314
include("utils.jl")
1415
export fastindices # Deprecated
1516

src/componentarray.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ function ComponentArray(data, ax::AbstractAxis...)
5858
return LazyArray(ComponentArray(x, axs...) for x in part_data)
5959
end
6060

61+
function Adapt.adapt_structure(to, x::ComponentArray)
62+
data = Adapt.adapt(to, getdata(x))
63+
return ComponentArray(data, getaxes(x))
64+
end
65+
66+
Adapt.adapt_storage(::Type{ComponentArray{T,N,A,Ax}}, xs::AT) where {T,N,A,Ax,AT<:AbstractArray} =
67+
Adapt.adapt_storage(A, xs)
68+
6169
# Entry from NamedTuple, Dict, or kwargs
6270
ComponentArray{T}(nt::NamedTuple) where T = ComponentArray(make_carray_args(T, nt)...)
6371
ComponentArray{T}(::NamedTuple{(), Tuple{}}) where T = ComponentArray(T[], (FlatAxis(),))
@@ -89,6 +97,8 @@ ComponentVector{T}(::UndefInitializer, ax) where {T} = ComponentArray{T}(undef,
8997
ComponentVector(data::AbstractVector, ax) = ComponentArray(data, ax)
9098
ComponentVector(data::AbstractArray, ax) = throw(DimensionMismatch("A `ComponentVector` must be initialized with a 1-dimensional array. This array is $(ndims(data))-dimensional."))
9199

100+
ConstructionBase.setproperties(x::ComponentVector, patch::NamedTuple) = ComponentVector(x; patch...)
101+
92102
# Add new fields to component Vector
93103
function ComponentArray(x::ComponentVector; kwargs...)
94104
return foldl((x1, kwarg) -> _maybe_add_field(x1, kwarg), (kwargs...,); init=x)

0 commit comments

Comments
 (0)