From 7a024c8e5f6c328e2e44185e135e17e364cdebeb Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Mon, 6 Jan 2020 14:49:53 +0000 Subject: [PATCH] test adapt --- Project.toml | 3 ++- src/compatibility.jl | 2 +- test/runtests.jl | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 638c0dae..f8ce5b70 100644 --- a/Project.toml +++ b/Project.toml @@ -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"] diff --git a/src/compatibility.jl b/src/compatibility.jl index d2f40aa3..f6e56e46 100644 --- a/src/compatibility.jl +++ b/src/compatibility.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index db46924c..40f4d1fd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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