Skip to content

Commit

Permalink
Move Adapt to a weak-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Dec 20, 2023
1 parent 62e0bd8 commit 204c686
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 9 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
name = "OffsetArrays"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.12.10"
version = "1.13.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

[weakdeps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

[extensions]
AdaptExt = "Adapt"

[compat]
Adapt = "2, 3, 4"
Aqua = "0.8"
Expand All @@ -20,6 +26,7 @@ Test = "<0.0.1, 1"
julia = "0.7, 1"

[extras]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CatIndices = "aafaddc9-749c-510e-ac4f-586e18779b91"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Expand All @@ -32,4 +39,4 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "CatIndices", "DistributedArrays", "DelimitedFiles", "Documenter", "Test", "LinearAlgebra", "EllipsisNotation", "StaticArrays", "FillArrays"]
test = ["Aqua", "CatIndices", "DistributedArrays", "DelimitedFiles", "Documenter", "Test", "LinearAlgebra", "EllipsisNotation", "StaticArrays", "FillArrays", "Adapt"]
11 changes: 11 additions & 0 deletions ext/AdaptExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module AdaptExt

using OffsetArrays, Adapt

##
# Adapt allows for automatic conversion of CPU OffsetArrays to GPU OffsetArrays
##
import Adapt
Adapt.adapt_structure(to, O::OffsetArray) = OffsetArrays.parent_call(x -> Adapt.adapt(to, x), O)

end
8 changes: 3 additions & 5 deletions src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,9 @@ if VERSION <= v"1.7.0-DEV.400"
Base._to_linear_index(A::OffsetArray) = first(LinearIndices(A))
end

##
# Adapt allows for automatic conversion of CPU OffsetArrays to GPU OffsetArrays
##
import Adapt
Adapt.adapt_structure(to, O::OffsetArray) = parent_call(x -> Adapt.adapt(to, x), O)
if !isdefined(Base, :get_extension)
include("../ext/AdaptExt.jl")
end

if Base.VERSION >= v"1.4.2"
include("precompile.jl")
Expand Down

0 comments on commit 204c686

Please sign in to comment.