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 Jul 21, 2023
1 parent 1cae070 commit 663c54d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
8 changes: 7 additions & 1 deletion 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"
Aqua = "0.6"
Expand Down
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 @@ -849,11 +849,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
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function same_value(r1, r2)
end

@testset "Project meta quality checks" begin
Aqua.test_all(OffsetArrays, piracy=false)
Aqua.test_all(OffsetArrays, piracy=false,
# only test formatting on VERSION >= v1.7
# https://github.com/JuliaTesting/Aqua.jl/issues/105#issuecomment-1551405866
project_toml_formatting = VERSION >= v"1.7")
if VERSION >= v"1.2"
doctest(OffsetArrays, manual = false)
end
Expand Down

0 comments on commit 663c54d

Please sign in to comment.