Skip to content

Commit 6090bf4

Browse files
authored
Move Adapt to a weak dependency (#331)
* Move Adapt to a weak-dependency * rename extension module
1 parent 62e0bd8 commit 6090bf4

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

Project.toml

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
name = "OffsetArrays"
22
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
3-
version = "1.12.10"
3+
version = "1.13.0"
44

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

8+
[weakdeps]
9+
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
10+
11+
[extensions]
12+
OffsetArraysAdaptExt = "Adapt"
13+
814
[compat]
915
Adapt = "2, 3, 4"
1016
Aqua = "0.8"
@@ -20,6 +26,7 @@ Test = "<0.0.1, 1"
2026
julia = "0.7, 1"
2127

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

3441
[targets]
35-
test = ["Aqua", "CatIndices", "DistributedArrays", "DelimitedFiles", "Documenter", "Test", "LinearAlgebra", "EllipsisNotation", "StaticArrays", "FillArrays"]
42+
test = ["Adapt", "Aqua", "CatIndices", "DistributedArrays", "DelimitedFiles", "Documenter", "EllipsisNotation", "FillArrays", "LinearAlgebra", "StaticArrays", "Test"]

ext/OffsetArraysAdaptExt.jl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module OffsetArraysAdaptExt
2+
3+
using OffsetArrays, Adapt
4+
5+
##
6+
# Adapt allows for automatic conversion of CPU OffsetArrays to GPU OffsetArrays
7+
##
8+
import Adapt
9+
Adapt.adapt_structure(to, O::OffsetArray) = OffsetArrays.parent_call(x -> Adapt.adapt(to, x), O)
10+
11+
end

src/OffsetArrays.jl

+3-5
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,9 @@ if VERSION <= v"1.7.0-DEV.400"
852852
Base._to_linear_index(A::OffsetArray) = first(LinearIndices(A))
853853
end
854854

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

861859
if Base.VERSION >= v"1.4.2"
862860
include("precompile.jl")

0 commit comments

Comments
 (0)