From 663c54d24b35e02a828790c39dc5f52431389fe9 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 15 May 2023 21:01:03 +0530 Subject: [PATCH] Move Adapt to a weak-dependency --- Project.toml | 8 +++++++- ext/AdaptExt.jl | 11 +++++++++++ src/OffsetArrays.jl | 8 +++----- test/runtests.jl | 5 ++++- 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 ext/AdaptExt.jl diff --git a/Project.toml b/Project.toml index 521235c..520e11e 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/ext/AdaptExt.jl b/ext/AdaptExt.jl new file mode 100644 index 0000000..1047a20 --- /dev/null +++ b/ext/AdaptExt.jl @@ -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 diff --git a/src/OffsetArrays.jl b/src/OffsetArrays.jl index 2a03bf5..a0f8829 100644 --- a/src/OffsetArrays.jl +++ b/src/OffsetArrays.jl @@ -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") diff --git a/test/runtests.jl b/test/runtests.jl index 300a18d..5012195 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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