Skip to content

Commit

Permalink
test adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Vertechi committed Jan 6, 2020
1 parent 78275ce commit 7a024c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ Tables = "0.2"
julia = "1"

[extras]
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
WeakRefStrings = "ea10d353-3f73-51f8-a26c-33c1cb351aa5"

[targets]
test = ["Test", "OffsetArrays", "PooledArrays", "WeakRefStrings"]
test = ["Test", "GPUArrays", "OffsetArrays", "PooledArrays", "WeakRefStrings"]
2 changes: 1 addition & 1 deletion src/compatibility.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GPU storage
import Adapt
Adapt.adapt_storage(to, s::StructArray) = replace_storage(x->Adapt.adapt(to, x), s)
Adapt.adapt_structure(to, s::StructArray) = replace_storage(x->Adapt.adapt(to, x), s)

# Table interface
import Tables
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ using StructArrays: staticschema, iscompatible, _promote_typejoin, append!!
using OffsetArrays: OffsetArray
import Tables, PooledArrays, WeakRefStrings
using DataAPI: refarray, refvalue
using Adapt: adapt
import GPUArrays
using Test

@testset "index" begin
Expand Down Expand Up @@ -693,3 +695,13 @@ end
@test vcat(dest, StructVector(makeitr())) == append!!(copy(dest), makeitr())
end
end

@testset "adapt" begin
s = StructArray(a = 1:10, b = StructArray(c = 1:10, d = 1:10))
t = adapt(Array, s)
@test propertynames(t) == (:a, :b)
@test s == t
@test t.a isa Array
@test t.b.c isa Array
@test t.b.d isa Array
end

0 comments on commit 7a024c8

Please sign in to comment.