diff --git a/Project.toml b/Project.toml index a0240a1..74663ae 100644 --- a/Project.toml +++ b/Project.toml @@ -4,7 +4,6 @@ version = "4.5.2" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -Requires = "ae029012-a4dd-5104-9daa-d747884805df" [weakdeps] SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" @@ -15,7 +14,6 @@ AdaptSparseArraysExt = "SparseArrays" AdaptStaticArraysExt = "StaticArrays" [compat] -Requires = "1" StaticArrays = "1" julia = "1.10" LinearAlgebra = "1" diff --git a/ext/AdaptSparseArraysExt.jl b/ext/AdaptSparseArraysExt.jl index 09ee7d0..7112f3a 100644 --- a/ext/AdaptSparseArraysExt.jl +++ b/ext/AdaptSparseArraysExt.jl @@ -1,7 +1,7 @@ module AdaptSparseArraysExt using Adapt -isdefined(Base, :get_extension) ? (using SparseArrays) : (using ..SparseArrays) +using SparseArrays Adapt.adapt_storage(::Type{Array}, xs::SparseVector) = xs Adapt.adapt_storage(::Type{Array}, xs::SparseMatrixCSC) = xs diff --git a/ext/AdaptStaticArraysExt.jl b/ext/AdaptStaticArraysExt.jl index 3f16da4..8d890f8 100644 --- a/ext/AdaptStaticArraysExt.jl +++ b/ext/AdaptStaticArraysExt.jl @@ -1,7 +1,7 @@ module AdaptStaticArraysExt using Adapt -isdefined(Base, :get_extension) ? (using StaticArrays) : (using ..StaticArrays) +using StaticArrays Adapt.adapt_storage(::Type{<:SArray{S}}, xs::Array) where {S} = SArray{S}(xs) Adapt.adapt_storage(::Type{SArray}, xs::Array) = SArray{Tuple{size(xs)...}}(xs) diff --git a/src/Adapt.jl b/src/Adapt.jl index fe5f817..fa744ec 100644 --- a/src/Adapt.jl +++ b/src/Adapt.jl @@ -46,13 +46,6 @@ Create a function that adapts its argument according to `to`. If no specific adaptions have been registered for `to`, the returned function will be equivalent to `identity`. """ adapt(to) = Base.Fix1(adapt, to) -if VERSION < v"1.9.0-DEV.857" - @eval function adapt(to::Type{T}) where {T} - (@isdefined T) || return Base.Fix1(adapt, to) - AT = Base.Fix1{typeof(adapt),Type{T}} - return $(Expr(:new, :AT, :adapt, :to)) - end -end adapt_structure(to, x) = adapt_storage(to, x) adapt_storage(to, x) = x @@ -67,19 +60,4 @@ include("arrays.jl") # helpers include("macro.jl") -if !isdefined(Base, :get_extension) -using Requires -end - -@static if !isdefined(Base, :get_extension) -function __init__() - @require SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" begin - include("../ext/AdaptSparseArraysExt.jl") - end - @require StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" begin - include("../ext/AdaptStaticArraysExt.jl") - end -end -end - end # module diff --git a/src/base.jl b/src/base.jl index 27292d5..ff1bb3c 100644 --- a/src/base.jl +++ b/src/base.jl @@ -49,10 +49,8 @@ end adapt_structure(to, x::Core.Box) = Core.Box(adapt(to, x.contents)) -if VERSION >= v"1.7" - # we can't rewrite opaque closures - adapt_structure(to, oc::Core.OpaqueClosure) = oc -end +# we can't rewrite opaque closures +adapt_structure(to, oc::Core.OpaqueClosure) = oc ## Broadcast diff --git a/src/wrappers.jl b/src/wrappers.jl index 1a34a22..24b8106 100644 --- a/src/wrappers.jl +++ b/src/wrappers.jl @@ -17,15 +17,10 @@ function adapt_structure(to, A::PermutedDimsArray) end adapt_structure(to, A::Base.ReshapedArray) = Base.reshape(adapt(to, parent(A)), size(A)) -@static if isdefined(Base, :NonReshapedReinterpretArray) - adapt_structure(to, A::Base.NonReshapedReinterpretArray) = - Base.reinterpret(eltype(A), adapt(to, parent(A))) - adapt_structure(to, A::Base.ReshapedReinterpretArray) = - Base.reinterpret(reshape, eltype(A), adapt(to, parent(A))) -else - adapt_structure(to, A::Base.ReinterpretArray) = - Base.reinterpret(eltype(A), adapt(to, parent(A))) -end +adapt_structure(to, A::Base.NonReshapedReinterpretArray) = + Base.reinterpret(eltype(A), adapt(to, parent(A))) +adapt_structure(to, A::Base.ReshapedReinterpretArray) = + Base.reinterpret(reshape, eltype(A), adapt(to, parent(A))) @eval function adapt_structure(to, A::Base.LogicalIndex{T}) where T # prevent re-calculating the count of booleans during LogicalIndex construction mask = adapt(to, A.mask) diff --git a/test/runtests.jl b/test/runtests.jl index 0e08935..32465aa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -140,9 +140,7 @@ inds = CustomArray{Int,1}([1,2]) @test_adapt CustomArray reinterpret(Int64,mat.arr) reinterpret(Int64,mat) AnyCustomArray -@static if isdefined(Base, :NonReshapedReinterpretArray) - @test_adapt CustomArray reinterpret(reshape,Int64,mat.arr) reinterpret(reshape,Int64,mat) AnyCustomArray -end +@test_adapt CustomArray reinterpret(reshape,Int64,mat.arr) reinterpret(reshape,Int64,mat) AnyCustomArray ## doubly-wrapped @@ -160,11 +158,9 @@ end @test_adapt CustomArray view(reshape(reinterpret(Int64,mat.arr), (2,2)), :, :) view(reshape(reinterpret(Int64,mat), (2,2)), :, :) AnyCustomArray @test_adapt CustomArray view(reshape(reinterpret(Int64,view(mat.arr,:,:)), (2,2)), :, :) view(reshape(reinterpret(Int64,view(mat,:,:)), (2,2)), :, :) AnyCustomArray -@static if isdefined(Base, :NonReshapedReinterpretArray) - @test_adapt CustomArray reinterpret(reshape,Int64,view(mat.arr,:,:)) reinterpret(reshape,Int64,view(mat,:,:)) AnyCustomArray - @test_adapt CustomArray view(reinterpret(reshape,Int64,mat.arr), :, :) view(reinterpret(reshape,Int64,mat), :, :) AnyCustomArray - @test_adapt CustomArray view(reinterpret(reshape,Int64,view(mat.arr,:,:)), :, :) view(reinterpret(reshape,Int64,view(mat,:,:)), :, :) AnyCustomArray -end +@test_adapt CustomArray reinterpret(reshape,Int64,view(mat.arr,:,:)) reinterpret(reshape,Int64,view(mat,:,:)) AnyCustomArray +@test_adapt CustomArray view(reinterpret(reshape,Int64,mat.arr), :, :) view(reinterpret(reshape,Int64,mat), :, :) AnyCustomArray +@test_adapt CustomArray view(reinterpret(reshape,Int64,view(mat.arr,:,:)), :, :) view(reinterpret(reshape,Int64,view(mat,:,:)), :, :) AnyCustomArray using LinearAlgebra