Skip to content

Commit

Permalink
Fix StaticArrays extension. (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored Feb 27, 2023
1 parent 47f5040 commit cd9d4b7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
15 changes: 8 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
name = "Adapt"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.6.0"
version = "3.6.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
Requires = "1"
julia = "1.6"
[weakdeps]
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[extensions]
AdaptStaticArraysExt = "StaticArrays"

[compat]
Requires = "1"
StaticArrays = "1"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[targets]
test = ["StaticArrays", "Test"]

[weakdeps]
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
5 changes: 3 additions & 2 deletions ext/AdaptStaticArraysExt.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module AdaptStaticArraysCoreExt
module AdaptStaticArraysExt

using Adapt
isdefined(Base, :get_extension) ? (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)

end
end
11 changes: 7 additions & 4 deletions src/Adapt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ include("arrays.jl")
# helpers
include("macro.jl")

import Requires
if !isdefined(Base, :get_extension)
using Requires
end

@static if !isdefined(Base, :get_extension)
function __init__()
Requires.@require StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" begin include("../ext/AdaptStaticArraysExt.jl") end
end
function __init__()
@require StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" begin include("../ext/AdaptStaticArraysExt.jl") end
end
end

end # module
8 changes: 6 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,9 @@ end

@testset "StaticArrays" begin
using StaticArrays
adapt(SArray, [1,2,3]) isa SArray
end
@test_adapt SArray{Tuple{3}} [1,2,3] SArray{Tuple{3}}([1,2,3])

# can't possibly infer this one, so not using @test_adapt
#@test_adapt SArray [1,2,3] SArray{Tuple{3}}([1,2,3])
@test adapt(SArray, [1,2,3]) === SArray{Tuple{3}}([1,2,3])
end

2 comments on commit cd9d4b7

@maleadt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/78604

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.6.1 -m "<description of version>" cd9d4b73459574722f8c493e86b16b1e6b3ada69
git push origin v3.6.1

Please sign in to comment.