-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And use curried adapter to avoid possible instability
- Loading branch information
Showing
3 changed files
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module StructArraysAdaptExt | ||
# Use Adapt allows for automatic conversion of CPU to GPU StructArrays | ||
using Adapt, StructArrays | ||
@static if !applicable(Adapt.adapt, Int) | ||
# Adapt.jl has curried support, implement it ourself | ||
adpat(to) = Base.Fix1(Adapt.adapt, to) | ||
if VERSION < v"1.9.0-DEV.857" | ||
@eval function adapt(to::Type{T}) where {T} | ||
(@isdefined T) || return Base.Fix1(Adapt.adapt, to) | ||
AT = Base.Fix1{typeof(Adapt.adapt),Type{T}} | ||
return $(Expr(:new, :AT, :(Adapt.adapt), :to)) | ||
end | ||
end | ||
end | ||
Adapt.adapt_structure(to, s::StructArray) = replace_storage(adapt(to), s) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters